pub fn convert(wareki: &str) -> Result<Option<DateTime<Utc>>, Error>Expand description
Converts Wareki (JIS X 0301) based date into ISO based one
Adding to the JIS X 0301 standard, some additional features are implemented for utility. such as:
- Accepts Full-width numbers
- Full-width numbers are also used along with Half-width.
- Accepts Non 0-padded patterns
- A leading 0 is generally omitted in practical use.
- Accepts first year notation in
"元年"- NOTE: In Japanese calendar system, the first year of each Gengo(元号; An
era name) is sometimes noted in
"元年"instead of<Era name>1年.
- NOTE: In Japanese calendar system, the first year of each Gengo(元号; An
era name) is sometimes noted in
§Example
use chrono::prelude::*;
use wareki_conv::conv::convert;
assert_eq!(
convert("明治1年2月3日").unwrap(),
Some(Utc.with_ymd_and_hms(1868, 2, 3, 0, 0, 0).unwrap())
);
assert_eq!(
convert("明治元年2月3日").unwrap(),
Some(Utc.with_ymd_and_hms(1868, 2, 3, 0, 0, 0).unwrap())
);
assert_eq!(
convert("令01.02.03").unwrap(),
Some(Utc.with_ymd_and_hms(2019, 2, 3, 0, 0, 0).unwrap())
);§Remark
Actually, the first day of each era is not January 1 and it differs for each era. For example, the first day of the Heisei is January 8. This library does not take such conditions into account and assumes that the input values are correct.