Module icu_calendar::gregorian

source ·
Expand description

This module contains types and implementations for the Gregorian calendar.

use icu::calendar::{gregorian::Gregorian, Date, DateTime};

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

// `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_gregorian = DateTime::new_from_iso(datetime_iso, Gregorian);

// `Date` checks
assert_eq!(date_gregorian.year().number, 1970);
assert_eq!(date_gregorian.month().ordinal, 1);
assert_eq!(date_gregorian.day_of_month().0, 2);

// `DateTime` checks
assert_eq!(datetime_gregorian.date.year().number, 1970);
assert_eq!(datetime_gregorian.date.month().ordinal, 1);
assert_eq!(datetime_gregorian.date.day_of_month().0, 2);
assert_eq!(datetime_gregorian.time.hour.number(), 13);
assert_eq!(datetime_gregorian.time.minute.number(), 1);
assert_eq!(datetime_gregorian.time.second.number(), 0);

Structs§

Functions§