Skip to content

Commit

Permalink
Rename locales feature to "unstable-locales" to make it easier to change
Browse files Browse the repository at this point in the history
  • Loading branch information
quodlibetor committed Jul 31, 2020
1 parent 6220e7f commit bc96105
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::*;
Expand Down
4 changes: 2 additions & 2 deletions ci/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -euo pipefail
source "${BASH_SOURCE[0]%/*}/_shlib.sh"

TEST_TZS=(ACST-9:30 EST4 UTC0 Asia/Katmandu)
FEATURES=(std serde clock "alloc serde" locales)
FEATURES=(std serde clock "alloc serde" unstable-locales)
RUST_113_FEATURES=(rustc-serialize serde)

main() {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
38 changes: 19 additions & 19 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -409,24 +409,24 @@ fn format_inner<'a>(
item: &Item<'a>,
_locale: Option<Locale>,
) -> 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",
Expand All @@ -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();
Expand Down Expand Up @@ -759,7 +759,7 @@ impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> DelayedFormat<I> {
}

/// 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<NaiveDate>,
time: Option<NaiveTime>,
Expand All @@ -770,7 +770,7 @@ impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> DelayedFormat<I> {
}

/// 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<Off>(
date: Option<NaiveDate>,
time: Option<NaiveTime>,
Expand All @@ -795,7 +795,7 @@ impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> DelayedFormat<I> {
#[cfg(any(feature = "alloc", feature = "std", test))]
impl<'a, I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>> fmt::Display for DelayedFormat<I> {
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(
Expand Down Expand Up @@ -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>,
Expand All @@ -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>,
Expand Down
28 changes: 14 additions & 14 deletions src/format/strftime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item<'a>>;
#[cfg(not(feature = "locales"))]
#[cfg(not(feature = "unstable-locales"))]
type Fmt<'a> = &'static [Item<'static>];

static D_FMT: &'static [Item<'static>] =
Expand Down Expand Up @@ -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();
Expand All @@ -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] = &[];

Expand All @@ -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,
Expand All @@ -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..];
Expand Down Expand Up @@ -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;
Expand All @@ -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..];
}
Expand Down Expand Up @@ -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);

Expand Down
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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;
Expand All @@ -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)]
Expand All @@ -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)]
Expand Down

0 comments on commit bc96105

Please sign in to comment.