Module icu_calendar::chinese

source ·
Expand description

This module contains types and implementations for the Chinese calendar.

use icu::calendar::{chinese::Chinese, Date, DateTime, Ref};

let chinese = Chinese::new();
let chinese = Ref(&chinese); // to avoid cloning

// `Date` type
let chinese_date =
    Date::try_new_chinese_date_with_calendar(4660, 6, 6, chinese)
        .expect("Failed to initialize Chinese Date instance.");

// `DateTime` type
let chinese_datetime = DateTime::try_new_chinese_datetime_with_calendar(
    4660, 6, 6, 13, 1, 0, chinese,
)
.expect("Failed to initialize Chinese DateTime instance");

// `Date` checks
assert_eq!(chinese_date.year().number, 4660);
assert_eq!(chinese_date.year().related_iso, Some(2023));
assert_eq!(chinese_date.year().cyclic.unwrap().get(), 40);
assert_eq!(chinese_date.month().ordinal, 6);
assert_eq!(chinese_date.day_of_month().0, 6);

// `DateTime` checks
assert_eq!(chinese_datetime.date.year().number, 4660);
assert_eq!(chinese_datetime.date.year().related_iso, Some(2023));
assert_eq!(chinese_datetime.date.year().cyclic.unwrap().get(), 40);
assert_eq!(chinese_datetime.date.month().ordinal, 6);
assert_eq!(chinese_datetime.date.day_of_month().0, 6);
assert_eq!(chinese_datetime.time.hour.number(), 13);
assert_eq!(chinese_datetime.time.minute.number(), 1);
assert_eq!(chinese_datetime.time.second.number(), 0);

Structs§

Type Aliases§