Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locales #453

Merged
merged 68 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f4b9ad8
Initial commit
cecton Jul 11, 2020
d150d93
Implement locales for format functions
cecton Jul 11, 2020
330edb6
WIP
cecton Jul 12, 2020
b4296af
WIP
cecton Jul 12, 2020
3777c97
Merge commit 130253ef2b914d300c1a0c6cff36cd3a5d846767 (no conflict)
cecton Jul 12, 2020
19f54ab
WIP
cecton Jul 12, 2020
870a7cc
WIP
cecton Jul 12, 2020
f27f6ce
WIP
cecton Jul 12, 2020
44e4fb1
WIP
cecton Jul 12, 2020
083575a
WIP
cecton Jul 12, 2020
9b7fd23
WIP
cecton Jul 12, 2020
61c17d7
WIP
cecton Jul 12, 2020
0213867
WIP
cecton Jul 12, 2020
1e6c086
WIP
cecton Jul 17, 2020
6de9c1a
WIP
cecton Jul 17, 2020
d10deae
WIP
cecton Jul 17, 2020
1f9648f
WIP
cecton Jul 17, 2020
26f3c77
WIP
cecton Jul 17, 2020
a65a2b3
WIP
cecton Jul 17, 2020
e4f16d7
WIP
cecton Jul 17, 2020
f32e4f2
WIP
cecton Jul 17, 2020
ee0853b
WIP
cecton Jul 17, 2020
3f2659e
WIP
cecton Jul 17, 2020
9085b05
WIP
cecton Jul 18, 2020
eacc085
WIP
cecton Jul 18, 2020
e6d601a
Update src/format/mod.rs
cecton Jul 18, 2020
aef41e9
Update src/format/mod.rs
cecton Jul 18, 2020
08be423
Update src/format/mod.rs
cecton Jul 18, 2020
a63d0cf
Update src/format/mod.rs
cecton Jul 18, 2020
12ca2c5
Update src/format/mod.rs
cecton Jul 18, 2020
3c02970
WIP
cecton Jul 19, 2020
72c960c
Update src/format/mod.rs
cecton Jul 19, 2020
be0cdd3
WIP
cecton Jul 19, 2020
048b144
WIP
cecton Jul 19, 2020
1acab1d
WIP
cecton Jul 19, 2020
2052de7
WIP
cecton Jul 19, 2020
1f2fd4f
WIP
cecton Jul 19, 2020
d786694
WIP
cecton Jul 19, 2020
1a80aa0
WIP
cecton Jul 19, 2020
3ef34a0
WIP
cecton Jul 19, 2020
3d52936
WIP
cecton Jul 19, 2020
e07be46
WIP
cecton Jul 19, 2020
5986e3a
WIP
cecton Jul 19, 2020
a417628
WIP
cecton Jul 19, 2020
9cb89fa
WIP
cecton Jul 19, 2020
5d1d9f1
WIP
cecton Jul 19, 2020
119c413
WIP
cecton Jul 19, 2020
790f9d5
Small clean-up
cecton Jul 19, 2020
87aa146
WIP
cecton Jul 24, 2020
2d9c1dc
Remove allow dead_code
cecton Jul 24, 2020
1dbb7fa
Merge commit 41345f10a1592ab9cc538a5cc7d7cad983d6a67c (no conflict)
cecton Jul 24, 2020
76fbfc2
Merge commit bfddc1e5fa9d40c1e9d9ab46fecb3bf7f39315e6 (conflicts)
cecton Jul 24, 2020
ffbb600
Merge branch 'locales' of github.com:cecton/chrono into locales
cecton Jul 24, 2020
dc66629
CLEANUP
cecton Jul 24, 2020
ab0c06a
WIP
cecton Jul 24, 2020
c7a491b
WIP
cecton Jul 24, 2020
16d29e4
Merge commit 53e63c3709332647811f1c738d5ba4a13980d439 (no conflict)
cecton Jul 24, 2020
ea3d20e
Update doc
cecton Jul 24, 2020
f6ecdcb
Revert "Update doc"
cecton Jul 26, 2020
2cdb6d3
Revert "WIP"
cecton Jul 26, 2020
05358ae
CLEANUP
cecton Jul 26, 2020
d1ae67b
WIP
cecton Jul 26, 2020
702c640
Merge commit 0579d2af083e3b73164fd799c424b0481c3823e7 (no conflict)
cecton Jul 26, 2020
90b3e8e
doc
cecton Jul 26, 2020
b6c5395
Doc comments
cecton Jul 26, 2020
6ebc477
Merge commit 38810a33bf4581adfc45a31156b77c3078cb04d7 (conflicts)
cecton Jul 30, 2020
6220e7f
Merge commit 370a20cb7130f9df53c2c50b1f965b58ba279729 (no conflict)
cecton Jul 30, 2020
bc96105
Rename locales feature to "unstable-locales" to make it easier to change
quodlibetor Jul 31, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Ben Boeckel <[email protected]>
Ben Eills <[email protected]>
Brandon W Maister <[email protected]>
Brandon W Maister <[email protected]>
Cecile Tonglet <[email protected]>
Colin Ray <[email protected]>
Corey Farwell <[email protected]>
Dan <[email protected]>
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Versions with only mechanical changes will be omitted from the following list.

## 0.4.14 (unreleased)

* Added locales. All format functions can now use locales.

## Improvements

* Added MIN and MAX values for `NaiveTime`, `NaiveDateTime` and `DateTime<Utc>`.
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ alloc = []
std = []
clock = ["time", "std"]
wasmbind = ["wasm-bindgen", "js-sys"]
locales = ["pure-rust-locales"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make this locales = ["pure-rust-locales", "alloc"] many feature gates will be more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know it is possible to do that, nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

__internal_bench = []
__doctest = []

Expand All @@ -38,6 +39,7 @@ num-integer = { version = "0.1.36", default-features = false }
num-traits = { version = "0.2", default-features = false }
rustc-serialize = { version = "0.3.20", optional = true }
serde = { version = "1.0.99", default-features = false, optional = true }
pure-rust-locales = { version = "0.2.1", optional = true }

[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
wasm-bindgen = { version = "0.2", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion 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")
FEATURES=(std serde clock "alloc serde" locales)
RUST_113_FEATURES=(rustc-serialize serde)

main() {
Expand Down
28 changes: 28 additions & 0 deletions src/format/locales.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use super::{FormatError, FormatErrorKind, FormatResult};

macro_rules! locale_match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice if this function lived in pure-rust-locales instead of here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

($locale:expr => $($item:ident)::+) => {{
match $locale {
"en_US" => Ok(pure_rust_locales::en_US::$($item)::+),
"fr_BE" => Ok(pure_rust_locales::fr_BE::$($item)::+),
// TODO: all the locales are available
_ => Err(FormatError(FormatErrorKind::UnknownLocale)),
}
}}
}

pub(crate) fn short_months(locale: &str) -> FormatResult<&[&'static str]> {
locale_match!(locale => LC_TIME::ABMON)
}

pub(crate) fn long_months(locale: &str) -> FormatResult<&[&'static str]> {
locale_match!(locale => LC_TIME::MON)
}

pub(crate) fn short_weekdays(locale: &str) -> FormatResult<&[&'static str]> {
locale_match!(locale => LC_TIME::ABDAY)
}

pub(crate) fn long_weekdays(locale: &str) -> FormatResult<&[&'static str]> {
locale_match!(locale => LC_TIME::DAY)
}
Loading