diff --git a/Cargo.toml b/Cargo.toml index 68237a0d8f..dd9dbeea97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ alloc = [] std = [] clock = ["time", "std"] wasmbind = ["wasm-bindgen", "js-sys"] -locales = ["pure-rust-locales", "alloc"] +unstable-locales = ["pure-rust-locales", "alloc"] __internal_bench = [] __doctest = [] diff --git a/README.md b/README.md index e642435af2..2e363f98bb 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,10 @@ Default features: Optional features: - `wasmbind`: Enable integration with [wasm-bindgen][] and its `js-sys` project -- [`serde`][]: Enable -- `locales`: Enable localization. +- [`serde`][]: Enable serialization/deserialization via serde. +- `unstable-locales`: Enable localization. This adds various methods with a + `_localized` suffix. The implementation and API may change or even be + removed in a patch release. Feedback welcome. [`serde`]: https://github.com/serde-rs/serde [wasm-bindgen]: https://github.com/rustwasm/wasm-bindgen @@ -228,13 +230,13 @@ for well-known formats. Chrono now also provides date formatting in almost any language without the help of an additional C library. This functionality is under the feature -`locales`: +`unstable-locales`: ```text -chrono { version = "0.4", features = ["locales"] +chrono { version = "0.4", features = ["unstable-locales"] ``` -The `locales` feature requires and implies at least the `alloc` feature. +The `unstable-locales` feature requires and implies at least the `alloc` feature. ```rust use chrono::prelude::*; diff --git a/ci/github.sh b/ci/github.sh index 486fb4457a..c99b1cfe7b 100755 --- a/ci/github.sh +++ b/ci/github.sh @@ -56,7 +56,7 @@ test_all_tzs() { test_regular() { tz="$1" && shift - runt env TZ="$tz" cargo test --features __doctest,locales --color=always -- --color=always + runt env TZ="$tz" cargo test --features __doctest,unstable-locales --color=always -- --color=always for feature in "${FEATURES[@]}"; do runt env TZ="$tz" cargo test --no-default-features --features "$feature" --lib --color=always -- --color=always done diff --git a/src/date.rs b/src/date.rs index 60a81de725..0012d36049 100644 --- a/src/date.rs +++ b/src/date.rs @@ -10,7 +10,7 @@ use core::ops::{Add, Sub}; use core::{fmt, hash}; use oldtime::Duration as OldDuration; -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] use format::Locale; #[cfg(any(feature = "alloc", feature = "std", test))] use format::{DelayedFormat, Item, StrftimeItems}; @@ -299,7 +299,7 @@ where } /// Formats the date with the specified formatting items and locale. - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] #[inline] pub fn format_localized_with_items<'a, I, B>( &self, @@ -322,7 +322,7 @@ where /// Formats the date with the specified format string and locale. /// See the [`format::strftime` module](./format/strftime/index.html) /// on the supported escape sequences. - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] #[inline] pub fn format_localized<'a>( &self, diff --git a/src/datetime.rs b/src/datetime.rs index dbca333564..f4a0cd13e6 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -19,7 +19,7 @@ use std::string::ToString; use core::borrow::Borrow; #[cfg(any(feature = "alloc", feature = "std", test))] use format::DelayedFormat; -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] use format::Locale; use format::{parse, ParseError, ParseResult, Parsed, StrftimeItems}; use format::{Fixed, Item}; @@ -497,7 +497,7 @@ where } /// Formats the combined date and time with the specified formatting items and locale. - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] #[inline] pub fn format_localized_with_items<'a, I, B>( &self, @@ -521,7 +521,7 @@ where /// Formats the combined date and time with the specified format string and locale. /// See the [`format::strftime` module](./format/strftime/index.html) /// on the supported escape sequences. - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] #[inline] pub fn format_localized<'a>( &self, diff --git a/src/format/mod.rs b/src/format/mod.rs index e8ac705c00..3fbc2dae34 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -36,17 +36,17 @@ use offset::{FixedOffset, Offset}; use {Datelike, Timelike}; use {Month, ParseMonthError, ParseWeekdayError, Weekday}; -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] pub(crate) mod locales; pub use self::parse::parse; pub use self::parsed::Parsed; pub use self::strftime::StrftimeItems; /// L10n locales. -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] pub use pure_rust_locales::Locale; -#[cfg(not(feature = "locales"))] +#[cfg(not(feature = "unstable-locales"))] #[derive(Debug)] struct Locale; @@ -409,24 +409,24 @@ fn format_inner<'a>( item: &Item<'a>, _locale: Option, ) -> fmt::Result { - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] let locale = _locale.unwrap_or(Locale::POSIX); - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] let short_months = locales::short_months(locale); - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] let long_months = locales::long_months(locale); - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] let short_weekdays = locales::short_weekdays(locale); - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] let long_weekdays = locales::long_weekdays(locale); - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] let am_pm = locales::am_pm(locale); - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] let short_months = &["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] let long_months = &[ "January", "February", @@ -441,12 +441,12 @@ fn format_inner<'a>( "November", "December", ]; - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] let short_weekdays = &["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] let long_weekdays = &["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] let am_pm = &["AM", "PM"]; let am_pm_lowercase: Vec<_> = am_pm.iter().map(|x| x.to_lowercase()).collect(); @@ -759,7 +759,7 @@ impl<'a, I: Iterator + Clone, B: Borrow>> DelayedFormat { } /// Makes a new `DelayedFormat` value out of local date and time and locale. - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] pub fn new_with_locale( date: Option, time: Option, @@ -770,7 +770,7 @@ impl<'a, I: Iterator + Clone, B: Borrow>> DelayedFormat { } /// Makes a new `DelayedFormat` value out of local date and time, UTC offset and locale. - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] pub fn new_with_offset_and_locale( date: Option, time: Option, @@ -795,7 +795,7 @@ impl<'a, I: Iterator + Clone, B: Borrow>> DelayedFormat { #[cfg(any(feature = "alloc", feature = "std", test))] impl<'a, I: Iterator + Clone, B: Borrow>> fmt::Display for DelayedFormat { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] { if let Some(locale) = self.locale { return format_localized( @@ -852,7 +852,7 @@ impl FromStr for Weekday { } /// Formats single formatting item -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] pub fn format_item_localized<'a>( w: &mut fmt::Formatter, date: Option<&NaiveDate>, @@ -868,7 +868,7 @@ pub fn format_item_localized<'a>( /// Tries to format given arguments with given formatting items. /// Internally used by `DelayedFormat`. -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] pub fn format_localized<'a, I, B>( w: &mut fmt::Formatter, date: Option<&NaiveDate>, diff --git a/src/format/strftime.rs b/src/format/strftime.rs index 6aa91192bc..0ca2ca9204 100644 --- a/src/format/strftime.rs +++ b/src/format/strftime.rs @@ -159,13 +159,13 @@ Notes: */ -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] use super::{locales, Locale}; use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric, Pad}; -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] type Fmt<'a> = Vec>; -#[cfg(not(feature = "locales"))] +#[cfg(not(feature = "unstable-locales"))] type Fmt<'a> = &'static [Item<'static>]; static D_FMT: &'static [Item<'static>] = @@ -212,7 +212,7 @@ impl<'a> StrftimeItems<'a> { } /// Creates a new parsing iterator from the `strftime`-like format string. - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] pub fn new_with_locale(s: &'a str, locale: Locale) -> StrftimeItems<'a> { let d_fmt = StrftimeItems::new(locales::d_fmt(locale)).collect(); let d_t_fmt = StrftimeItems::new(locales::d_t_fmt(locale)).collect(); @@ -227,7 +227,7 @@ impl<'a> StrftimeItems<'a> { } } - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] fn with_remainer(s: &'a str) -> StrftimeItems<'a> { static FMT_NONE: &'static [Item<'static>; 0] = &[]; @@ -240,7 +240,7 @@ impl<'a> StrftimeItems<'a> { } } - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] fn with_remainer(s: &'a str) -> StrftimeItems<'a> { StrftimeItems { remainder: s, @@ -261,11 +261,11 @@ impl<'a> Iterator for StrftimeItems<'a> { // we have some reconstructed items to return if !self.recons.is_empty() { let item; - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] { item = self.recons.remove(0); } - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] { item = self.recons[0].clone(); self.recons = &self.recons[1..]; @@ -308,12 +308,12 @@ impl<'a> Iterator for StrftimeItems<'a> { macro_rules! recons { [$head:expr, $($tail:expr),+ $(,)*] => ({ - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] { self.recons.clear(); $(self.recons.push($tail);)+ } - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] { const RECONS: &'static [Item<'static>] = &[$($tail),+]; self.recons = RECONS; @@ -324,12 +324,12 @@ impl<'a> Iterator for StrftimeItems<'a> { macro_rules! recons_from_slice { ($slice:expr) => {{ - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] { self.recons.clear(); self.recons.extend_from_slice(&$slice[1..]); } - #[cfg(not(feature = "locales"))] + #[cfg(not(feature = "unstable-locales"))] { self.recons = &$slice[1..]; } @@ -606,10 +606,10 @@ fn test_strftime_docs() { assert_eq!(dt.format("%%").to_string(), "%"); } -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] #[test] fn test_strftime_docs_localized() { - use {FixedOffset, TimeZone, Timelike}; + use {FixedOffset, TimeZone}; let dt = FixedOffset::east(34200).ymd(2001, 7, 8).and_hms_nano(0, 34, 59, 1_026_490_708); diff --git a/src/lib.rs b/src/lib.rs index dd408d856c..89ffd87acd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,8 +48,10 @@ //! Optional features: //! //! - `wasmbind`: Enable integration with [wasm-bindgen][] and its `js-sys` project -//! - [`serde`][]: Enable -//! - `locales`: Enable localization. +//! - [`serde`][]: Enable serialization/deserialization via serde. +//! - `unstable-locales`: Enable localization. This adds various methods with a +//! `_localized` suffix. The implementation and API may change or even be +//! removed in a patch release. Feedback welcome. //! //! [`serde`]: https://github.com/serde-rs/serde //! [wasm-bindgen]: https://github.com/rustwasm/wasm-bindgen @@ -220,13 +222,13 @@ //! //! Chrono now also provides date formatting in almost any language without the //! help of an additional C library. This functionality is under the feature -//! `locales`: +//! `unstable-locales`: //! //! ```text -//! chrono { version = "0.4", features = ["locales"] +//! chrono { version = "0.4", features = ["unstable-locales"] //! ``` //! -//! The `locales` feature requires and implies at least the `alloc` feature. +//! The `unstable-locales` feature requires and implies at least the `alloc` feature. //! //! ```rust //! use chrono::prelude::*; @@ -452,7 +454,7 @@ extern crate serde as serdelib; extern crate doc_comment; #[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))] extern crate js_sys; -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] extern crate pure_rust_locales; #[cfg(feature = "bench")] extern crate test; @@ -471,7 +473,7 @@ pub use date::{Date, MAX_DATE, MIN_DATE}; pub use datetime::rustc_serialize::TsSeconds; pub use datetime::{DateTime, SecondsFormat, MAX_DATETIME, MIN_DATETIME}; /// L10n locales. -#[cfg(feature = "locales")] +#[cfg(feature = "unstable-locales")] pub use format::Locale; pub use format::{ParseError, ParseResult}; #[doc(no_inline)] @@ -490,7 +492,7 @@ pub mod prelude { #[cfg(feature = "clock")] #[doc(no_inline)] pub use Local; - #[cfg(feature = "locales")] + #[cfg(feature = "unstable-locales")] #[doc(no_inline)] pub use Locale; #[doc(no_inline)]