Expand description
This is an extension to chrono’s date and time formatting to automatically translate dates to a specified locale or language
§Usage
Put this in your Cargo.toml:
[dependencies]
chrono = "0.4"
chrono_lc = "0.1.7"Then put this in your lib.rs or main.rs:
use chrono::prelude::*;
use chrono_lc::LocaleDate;You can choose to import just parts of chrono instead of the whole prelude. Please see ’chrono`’s documentation.
To format a chrono Date or DateTime object, you can use the formatl method:
let dt = FixedOffset::east_opt(34200)
.unwrap()
.with_ymd_and_hms(2001, 7, 8, 0, 34, 59)
.unwrap()
.with_nanosecond(1_026_490_708)
.unwrap();
println!("{}", dt.formatl("%c", "fr"));All of chrono’s formatting placeholders
work except for %3f, %6f and %9f (but %.3f, %.6f and %.9f work normally)
§Locale format
The formatl method supports locales in different formats, based on ISO-639-1 and ISO-3166.
It accepts any format where they are separated by - or _:
- en_GB
- it-IT
- fr-fr
- PT_br
The translated string will be first searched in the complete locale definition, then in the fallbacks.
For example: by requesting it_IT it will first try in it-it, then in it and, if it still
doesn’t find it, it will use the default: C (english)
Structs§
- Delayed
Format L10n - A temporary object which can be used as an argument to
format!or others. This is normally constructed viaformatmethods of each date and time type.
Traits§
Functions§
- format_
l10n - This function is nearly entirely copied from chrono’s format() internal formats (3, 6 and 9-digits nanoseconds) have been disabled due to lack of access to chrono internals