Module japanese

Source
Expand description

This module contains types and implementations for the Japanese calendar.

use icu::calendar::japanese::Japanese;
use icu::calendar::{types::Era, Date, DateTime};
use tinystr::tinystr;

let japanese_calendar = Japanese::new();

// `Date` type
let date_iso = Date::try_new_iso_date(1970, 1, 2)
    .expect("Failed to initialize ISO Date instance.");
let date_japanese = Date::new_from_iso(date_iso, japanese_calendar.clone());

// `DateTime` type
let datetime_iso = DateTime::try_new_iso_datetime(1970, 1, 2, 13, 1, 0)
    .expect("Failed to initialize ISO DateTime instance.");
let datetime_japanese =
    DateTime::new_from_iso(datetime_iso, japanese_calendar.clone());

// `Date` checks
assert_eq!(date_japanese.year().number, 45);
assert_eq!(date_japanese.month().ordinal, 1);
assert_eq!(date_japanese.day_of_month().0, 2);
assert_eq!(date_japanese.year().era, Era(tinystr!(16, "showa")));

// `DateTime` type
assert_eq!(datetime_japanese.date.year().number, 45);
assert_eq!(datetime_japanese.date.month().ordinal, 1);
assert_eq!(datetime_japanese.date.day_of_month().0, 2);
assert_eq!(
    datetime_japanese.date.year().era,
    Era(tinystr!(16, "showa"))
);
assert_eq!(datetime_japanese.time.hour.number(), 13);
assert_eq!(datetime_japanese.time.minute.number(), 1);
assert_eq!(datetime_japanese.time.second.number(), 0);

Structsยง

Japanese
The Japanese Calendar (with modern eras only)
JapaneseDateInner
The inner date type used for representing Dates of Japanese. See Date and Japanese for more details.
JapaneseExtended
The Japanese Calendar (with historical eras)

Constantsยง

FALLBACK_ERA ๐Ÿ”’
HEISEI_START ๐Ÿ”’
MEIJI_START ๐Ÿ”’
REIWA_START ๐Ÿ”’
SHOWA_START ๐Ÿ”’
TAISHO_START ๐Ÿ”’