diff --git a/Cargo.toml b/Cargo.toml index ca9a478..005b3ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "chrono-locale" version = "0.1.0" authors = ["Alessandro Pellizzari "] +# build = "build.rs" [dependencies] chrono = "0.4" @@ -11,4 +12,5 @@ lazy_static = "1.2" [build-dependencies] serde = "1" serde_json = "1" +serde_derive = "1" walkdir = "2" diff --git a/rustfmt.toml b/rustfmt.toml index cc8500e..0cf6f8f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,5 +1,5 @@ max_width = 150 hard_tabs = true -normalize_comments = false -match_block_trailing_comma = true -closure_block_indent_threshold = 1 +#normalize_comments = false +#match_block_trailing_comma = true +#closure_block_indent_threshold = 1 diff --git a/src/lib.rs b/src/lib.rs index 6fc863a..65361ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,8 +65,7 @@ impl<'a, I: Iterator> + Clone> DelayedFormatL10n { } /// Makes a new `DelayedFormatL10n` value out of local date and time and UTC offset. - pub fn new_with_offset(date: Option, time: Option, offset: &FixedOffset, items: I, locale: &str) -> DelayedFormatL10n - { + pub fn new_with_offset(date: Option, time: Option, offset: &FixedOffset, items: I, locale: &str) -> DelayedFormatL10n { let name_and_diff = (offset.to_string(), offset.to_owned()); DelayedFormatL10n { date, @@ -273,28 +272,36 @@ where } fn short_month(month: usize, locale: &str) -> String { - let res = locales::LOCALES.short_months.get(locale) + let res = locales::LOCALES + .short_months + .get(locale) .or_else(|| locales::LOCALES.short_months.get("C")) .unwrap(); res.get(month).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", month)) } fn long_month(month: usize, locale: &str) -> String { - let res = locales::LOCALES.long_months.get(locale) + let res = locales::LOCALES + .long_months + .get(locale) .or_else(|| locales::LOCALES.long_months.get("C")) .unwrap(); res.get(month).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", month)) } fn short_weekday(day: usize, locale: &str) -> String { - let res = locales::LOCALES.short_weekdays.get(locale) + let res = locales::LOCALES + .short_weekdays + .get(locale) .or_else(|| locales::LOCALES.short_weekdays.get("C")) .unwrap(); res.get(day).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", day)) } fn long_weekday(day: usize, locale: &str) -> String { - let res = locales::LOCALES.long_weekdays.get(locale) + let res = locales::LOCALES + .long_weekdays + .get(locale) .or_else(|| locales::LOCALES.long_weekdays.get("C")) .unwrap(); res.get(day).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", day)) @@ -355,9 +362,9 @@ mod tests { assert_eq!(dt.formatl("%.6f", "en").to_string(), ".026490"); assert_eq!(dt.formatl("%.9f", "en").to_string(), ".026490708"); // The following formats are not exposed by chrono and cannot be formatted -// assert_eq!(dt.formatl("%3f", "en").to_string(), "026"); -// assert_eq!(dt.formatl("%6f", "en").to_string(), "026490"); -// assert_eq!(dt.formatl("%9f", "en").to_string(), "026490708"); + // assert_eq!(dt.formatl("%3f", "en").to_string(), "026"); + // assert_eq!(dt.formatl("%6f", "en").to_string(), "026490"); + // assert_eq!(dt.formatl("%9f", "en").to_string(), "026490708"); assert_eq!(dt.formatl("%R", "en").to_string(), "00:34"); assert_eq!(dt.formatl("%T", "en").to_string(), "00:34:60"); assert_eq!(dt.formatl("%X", "en").to_string(), "00:34:60"); diff --git a/src/locales.rs b/src/locales.rs index 1b0b67d..e34e5a7 100644 --- a/src/locales.rs +++ b/src/locales.rs @@ -11,33 +11,43 @@ pub struct Locales { lazy_static! { pub static ref LOCALES: Locales = { - let mut res = Locales{ + let mut res = Locales { short_months: HashMap::new(), long_months: HashMap::new(), short_weekdays: HashMap::new(), long_weekdays: HashMap::new(), }; - res.short_months.insert("C".into(), vec!["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]); + res.short_months.insert( + "C".into(), + vec!["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], + ); - res.long_months.insert("C".into(), vec![ - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", - ]); + res.long_months.insert( + "C".into(), + vec![ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ], + ); - res.short_weekdays.insert("C".into(), vec!["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]); + res.short_weekdays + .insert("C".into(), vec!["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]); - res.long_weekdays.insert("C".into(), vec!["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]); + res.long_weekdays.insert( + "C".into(), + vec!["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], + ); res };