mirror of
https://github.com/0x5eal/chrono-lc.git
synced 2024-12-12 12:50:36 +00:00
Cleanup
This commit is contained in:
parent
c70481d776
commit
64ea230a2b
4 changed files with 49 additions and 30 deletions
|
@ -2,6 +2,7 @@
|
||||||
name = "chrono-locale"
|
name = "chrono-locale"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Alessandro Pellizzari <alex@amiran.it>"]
|
authors = ["Alessandro Pellizzari <alex@amiran.it>"]
|
||||||
|
# build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
@ -11,4 +12,5 @@ lazy_static = "1.2"
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
serde_derive = "1"
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
max_width = 150
|
max_width = 150
|
||||||
hard_tabs = true
|
hard_tabs = true
|
||||||
normalize_comments = false
|
#normalize_comments = false
|
||||||
match_block_trailing_comma = true
|
#match_block_trailing_comma = true
|
||||||
closure_block_indent_threshold = 1
|
#closure_block_indent_threshold = 1
|
||||||
|
|
19
src/lib.rs
19
src/lib.rs
|
@ -65,8 +65,7 @@ impl<'a, I: Iterator<Item = Item<'a>> + Clone> DelayedFormatL10n<I> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Makes a new `DelayedFormatL10n` value out of local date and time and UTC offset.
|
/// Makes a new `DelayedFormatL10n` value out of local date and time and UTC offset.
|
||||||
pub fn new_with_offset(date: Option<NaiveDate>, time: Option<NaiveTime>, offset: &FixedOffset, items: I, locale: &str) -> DelayedFormatL10n<I>
|
pub fn new_with_offset(date: Option<NaiveDate>, time: Option<NaiveTime>, offset: &FixedOffset, items: I, locale: &str) -> DelayedFormatL10n<I> {
|
||||||
{
|
|
||||||
let name_and_diff = (offset.to_string(), offset.to_owned());
|
let name_and_diff = (offset.to_string(), offset.to_owned());
|
||||||
DelayedFormatL10n {
|
DelayedFormatL10n {
|
||||||
date,
|
date,
|
||||||
|
@ -273,28 +272,36 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn short_month(month: usize, locale: &str) -> String {
|
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"))
|
.or_else(|| locales::LOCALES.short_months.get("C"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
res.get(month).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", month))
|
res.get(month).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", month))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn long_month(month: usize, locale: &str) -> String {
|
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"))
|
.or_else(|| locales::LOCALES.long_months.get("C"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
res.get(month).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", month))
|
res.get(month).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", month))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn short_weekday(day: usize, locale: &str) -> String {
|
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"))
|
.or_else(|| locales::LOCALES.short_weekdays.get("C"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
res.get(day).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", day))
|
res.get(day).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", day))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn long_weekday(day: usize, locale: &str) -> String {
|
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"))
|
.or_else(|| locales::LOCALES.long_weekdays.get("C"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
res.get(day).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", day))
|
res.get(day).map(|v| v.to_string()).unwrap_or_else(|| format!("{}", day))
|
||||||
|
|
|
@ -18,9 +18,14 @@ lazy_static! {
|
||||||
long_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![
|
res.long_months.insert(
|
||||||
|
"C".into(),
|
||||||
|
vec![
|
||||||
"January",
|
"January",
|
||||||
"February",
|
"February",
|
||||||
"March",
|
"March",
|
||||||
|
@ -33,11 +38,16 @@ lazy_static! {
|
||||||
"October",
|
"October",
|
||||||
"November",
|
"November",
|
||||||
"December",
|
"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
|
res
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue