Name Description Size
any_calendar.rs Module for working with multiple calendars at once 70235
buddhist.rs This module contains types and implementations for the Buddhist calendar. ```rust use icu::calendar::{buddhist::Buddhist, Date, DateTime}; // `Date` type let date_iso = Date::try_new_iso_date(1970, 1, 2) .expect("Failed to initialize ISO Date instance."); let date_buddhist = Date::new_from_iso(date_iso, Buddhist); // `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_buddhist = DateTime::new_from_iso(datetime_iso, Buddhist); // `Date` checks assert_eq!(date_buddhist.year().number, 2513); assert_eq!(date_buddhist.month().ordinal, 1); assert_eq!(date_buddhist.day_of_month().0, 2); // `DateTime` type assert_eq!(datetime_buddhist.date.year().number, 2513); assert_eq!(datetime_buddhist.date.month().ordinal, 1); assert_eq!(datetime_buddhist.date.day_of_month().0, 2); assert_eq!(datetime_buddhist.time.hour.number(), 13); assert_eq!(datetime_buddhist.time.minute.number(), 1); assert_eq!(datetime_buddhist.time.second.number(), 0); ``` 15299
calendar.rs 4078
calendar_arithmetic.rs 15274
chinese.rs This module contains types and implementations for the Chinese calendar. ```rust 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); ``` 40062
chinese_based.rs This module contains types and traits for use in the Chinese traditional lunar calendar, as well as in related and derived calendars such as the Korean and Vietnamese lunar calendars. ```rust use icu::calendar::{chinese::Chinese, Date, Iso}; let iso_date = Date::try_new_iso_date(2023, 6, 23).unwrap(); let chinese_date = Date::new_from_iso(iso_date, Chinese::new()); 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); ``` 24881
coptic.rs This module contains types and implementations for the Coptic calendar. ```rust use icu::calendar::{coptic::Coptic, Date, DateTime}; // `Date` type let date_iso = Date::try_new_iso_date(1970, 1, 2) .expect("Failed to initialize ISO Date instance."); let date_coptic = Date::new_from_iso(date_iso, Coptic); // `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_coptic = DateTime::new_from_iso(datetime_iso, Coptic); // `Date` checks assert_eq!(date_coptic.year().number, 1686); assert_eq!(date_coptic.month().ordinal, 4); assert_eq!(date_coptic.day_of_month().0, 24); // `DateTime` type assert_eq!(datetime_coptic.date.year().number, 1686); assert_eq!(datetime_coptic.date.month().ordinal, 4); assert_eq!(datetime_coptic.date.day_of_month().0, 24); assert_eq!(datetime_coptic.time.hour.number(), 13); assert_eq!(datetime_coptic.time.minute.number(), 1); assert_eq!(datetime_coptic.time.second.number(), 0); ``` 10461
dangi.rs This module contains types and implementations for the Korean Dangi calendar. ```rust use icu::calendar::dangi::Dangi; use icu::calendar::{Date, DateTime, Ref}; let dangi = Dangi::new(); let dangi = Ref(&dangi); // to avoid cloning // `Date` type let dangi_date = Date::try_new_dangi_date_with_calendar(4356, 6, 6, dangi) .expect("Failed to initialize Dangi Date instance."); // `DateTime` type let dangi_datetime = DateTime::try_new_dangi_datetime_with_calendar( 4356, 6, 6, 13, 1, 0, dangi, ) .expect("Failed to initialize Dangi DateTime instance."); // `Date` checks assert_eq!(dangi_date.year().number, 4356); assert_eq!(dangi_date.year().related_iso, Some(2023)); assert_eq!(dangi_date.year().cyclic.unwrap().get(), 40); assert_eq!(dangi_date.month().ordinal, 6); assert_eq!(dangi_date.day_of_month().0, 6); // `DateTime` checks assert_eq!(dangi_datetime.date.year().number, 4356); assert_eq!(dangi_datetime.date.year().related_iso, Some(2023)); assert_eq!(dangi_datetime.date.year().cyclic.unwrap().get(), 40); assert_eq!(dangi_datetime.date.month().ordinal, 6); assert_eq!(dangi_datetime.date.day_of_month().0, 6); assert_eq!(dangi_datetime.time.hour.number(), 13); assert_eq!(dangi_datetime.time.minute.number(), 1); assert_eq!(dangi_datetime.time.second.number(), 0); ``` 34255
date.rs 13630
datetime.rs 6429
duration.rs 4911
error.rs 3242
ethiopian.rs This module contains types and implementations for the Ethiopian calendar. ```rust use icu::calendar::{ethiopian::Ethiopian, Date, DateTime}; // `Date` type let date_iso = Date::try_new_iso_date(1970, 1, 2) .expect("Failed to initialize ISO Date instance."); let date_ethiopian = Date::new_from_iso(date_iso, Ethiopian::new()); // `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_ethiopian = DateTime::new_from_iso(datetime_iso, Ethiopian::new()); // `Date` checks assert_eq!(date_ethiopian.year().number, 1962); assert_eq!(date_ethiopian.month().ordinal, 4); assert_eq!(date_ethiopian.day_of_month().0, 24); // `DateTime` type assert_eq!(datetime_ethiopian.date.year().number, 1962); assert_eq!(datetime_ethiopian.date.month().ordinal, 4); assert_eq!(datetime_ethiopian.date.day_of_month().0, 24); assert_eq!(datetime_ethiopian.time.hour.number(), 13); assert_eq!(datetime_ethiopian.time.minute.number(), 1); assert_eq!(datetime_ethiopian.time.second.number(), 0); ``` 14721
gregorian.rs This module contains types and implementations for the Gregorian calendar. ```rust 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); ``` 20869
hebrew.rs This module contains types and implementations for the Hebrew calendar. ```rust use icu::calendar::{Date, DateTime}; // `Date` type let hebrew_date = Date::try_new_hebrew_date(3425, 10, 11) .expect("Failed to initialize hebrew Date instance."); // `DateTime` type let hebrew_datetime = DateTime::try_new_hebrew_datetime(3425, 10, 11, 13, 1, 0) .expect("Failed to initialize hebrew DateTime instance."); // `Date` checks assert_eq!(hebrew_date.year().number, 3425); assert_eq!(hebrew_date.month().ordinal, 10); assert_eq!(hebrew_date.day_of_month().0, 11); // `DateTime` checks assert_eq!(hebrew_datetime.date.year().number, 3425); assert_eq!(hebrew_datetime.date.month().ordinal, 10); assert_eq!(hebrew_datetime.date.day_of_month().0, 11); assert_eq!(hebrew_datetime.time.hour.number(), 13); assert_eq!(hebrew_datetime.time.minute.number(), 1); assert_eq!(hebrew_datetime.time.second.number(), 0); ``` 20674
indian.rs This module contains types and implementations for the Indian national calendar. ```rust use icu::calendar::{indian::Indian, Date, DateTime}; // `Date` type let date_iso = Date::try_new_iso_date(1970, 1, 2) .expect("Failed to initialize ISO Date instance."); let date_indian = Date::new_from_iso(date_iso, Indian); // `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_indian = DateTime::new_from_iso(datetime_iso, Indian); // `Date` checks assert_eq!(date_indian.year().number, 1891); assert_eq!(date_indian.month().ordinal, 10); assert_eq!(date_indian.day_of_month().0, 12); // `DateTime` type assert_eq!(datetime_indian.date.year().number, 1891); assert_eq!(datetime_indian.date.month().ordinal, 10); assert_eq!(datetime_indian.date.day_of_month().0, 12); assert_eq!(datetime_indian.time.hour.number(), 13); assert_eq!(datetime_indian.time.minute.number(), 1); assert_eq!(datetime_indian.time.second.number(), 0); ``` 18249
islamic.rs This module contains types and implementations for the Islamic calendars. ```rust use icu::calendar::islamic::IslamicObservational; use icu::calendar::{Date, DateTime, Ref}; let islamic = IslamicObservational::new_always_calculating(); let islamic = Ref(&islamic); // to avoid cloning // `Date` type let islamic_date = Date::try_new_observational_islamic_date(1348, 10, 11, islamic) .expect("Failed to initialize islamic Date instance."); // `DateTime` type let islamic_datetime = DateTime::try_new_observational_islamic_datetime( 1348, 10, 11, 13, 1, 0, islamic, ) .expect("Failed to initialize islamic DateTime instance."); // `Date` checks assert_eq!(islamic_date.year().number, 1348); assert_eq!(islamic_date.month().ordinal, 10); assert_eq!(islamic_date.day_of_month().0, 11); // `DateTime` checks assert_eq!(islamic_datetime.date.year().number, 1348); assert_eq!(islamic_datetime.date.month().ordinal, 10); assert_eq!(islamic_datetime.date.day_of_month().0, 11); assert_eq!(islamic_datetime.time.hour.number(), 13); assert_eq!(islamic_datetime.time.minute.number(), 1); assert_eq!(islamic_datetime.time.second.number(), 0); ``` 66142
iso.rs This module contains types and implementations for the ISO calendar. ```rust use icu::calendar::{Date, DateTime}; // `Date` type let date_iso = Date::try_new_iso_date(1970, 1, 2) .expect("Failed to initialize ISO Date instance."); // `DateTime` type let datetime_iso = DateTime::try_new_iso_datetime(1970, 1, 2, 13, 1, 0) .expect("Failed to initialize ISO DateTime instance."); // `Date` checks assert_eq!(date_iso.year().number, 1970); assert_eq!(date_iso.month().ordinal, 1); assert_eq!(date_iso.day_of_month().0, 2); // `DateTime` type assert_eq!(datetime_iso.date.year().number, 1970); assert_eq!(datetime_iso.date.month().ordinal, 1); assert_eq!(datetime_iso.date.day_of_month().0, 2); assert_eq!(datetime_iso.time.hour.number(), 13); assert_eq!(datetime_iso.time.minute.number(), 1); assert_eq!(datetime_iso.time.second.number(), 0); ``` 29231
japanese.rs This module contains types and implementations for the Japanese calendar. ```rust 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); ``` 34966
julian.rs This module contains types and implementations for the Julian calendar. ```rust use icu::calendar::{julian::Julian, Date, DateTime}; // `Date` type let date_iso = Date::try_new_iso_date(1970, 1, 2) .expect("Failed to initialize ISO Date instance."); let date_julian = Date::new_from_iso(date_iso, Julian); // `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_julian = DateTime::new_from_iso(datetime_iso, Julian); // `Date` checks assert_eq!(date_julian.year().number, 1969); assert_eq!(date_julian.month().ordinal, 12); assert_eq!(date_julian.day_of_month().0, 20); // `DateTime` type assert_eq!(datetime_julian.date.year().number, 1969); assert_eq!(datetime_julian.date.month().ordinal, 12); assert_eq!(datetime_julian.date.day_of_month().0, 20); assert_eq!(datetime_julian.time.hour.number(), 13); assert_eq!(datetime_julian.time.minute.number(), 1); assert_eq!(datetime_julian.time.second.number(), 0); ``` 20141
lib.rs Types for dealing with dates, times, and custom calendars. This module is published as its own crate ([`icu_calendar`](https://docs.rs/icu_calendar/latest/icu_calendar/)) and as part of the [`icu`](https://docs.rs/icu/latest/icu/) crate. See the latter for more details on the ICU4X project. The [`types`] module has a lot of common types for dealing with dates and times. [`Calendar`] is a trait that allows one to define custom calendars, and [`Date`] can represent dates for arbitrary calendars. The [`iso`] and [`gregorian`] modules contain implementations for the ISO and Gregorian calendars respectively. Further calendars can be found in modules like [`japanese`], [`julian`], [`coptic`], [`indian`], [`buddhist`], and [`ethiopian`]. Most interaction with this crate will be done via the [`Date`] and [`DateTime`] types. Some of the algorithms implemented here are based on Dershowitz, Nachum, and Edward M. Reingold. _Calendrical calculations_. Cambridge University Press, 2008. with associated Lisp code found at <https://github.com/EdReingold/calendar-code2>. # Examples Examples of date manipulation using `Date` object. `Date` objects are useful for working with dates, encompassing information about the day, month, year, as well as the calendar type. ```rust use icu::calendar::{types::IsoWeekday, Date}; // Creating ISO date: 1992-09-02. let mut date_iso = Date::try_new_iso_date(1992, 9, 2) .expect("Failed to initialize ISO Date instance."); assert_eq!(date_iso.day_of_week(), IsoWeekday::Wednesday); assert_eq!(date_iso.year().number, 1992); assert_eq!(date_iso.month().ordinal, 9); assert_eq!(date_iso.day_of_month().0, 2); // Answering questions about days in month and year. assert_eq!(date_iso.days_in_year(), 366); assert_eq!(date_iso.days_in_month(), 30); ``` Example of converting an ISO date across Indian and Buddhist calendars. ```rust use icu::calendar::{buddhist::Buddhist, indian::Indian, Date}; // Creating ISO date: 1992-09-02. let mut date_iso = Date::try_new_iso_date(1992, 9, 2) .expect("Failed to initialize ISO Date instance."); assert_eq!(date_iso.year().number, 1992); assert_eq!(date_iso.month().ordinal, 9); assert_eq!(date_iso.day_of_month().0, 2); // Conversion into Indian calendar: 1914-08-02. let date_indian = date_iso.to_calendar(Indian); assert_eq!(date_indian.year().number, 1914); assert_eq!(date_indian.month().ordinal, 6); assert_eq!(date_indian.day_of_month().0, 11); // Conversion into Buddhist calendar: 2535-09-02. let date_buddhist = date_iso.to_calendar(Buddhist); assert_eq!(date_buddhist.year().number, 2535); assert_eq!(date_buddhist.month().ordinal, 9); assert_eq!(date_buddhist.day_of_month().0, 2); ``` Example using `DateTime` object. Similar to `Date` objects, `DateTime` objects contain an accessible `Date` object containing information about the day, month, year, and calendar type. Additionally, `DateTime` objects contain an accessible `Time` object, including granularity of hour, minute, second, and nanosecond. ```rust use icu::calendar::{types::IsoWeekday, DateTime, Time}; // Creating ISO date: 1992-09-02 8:59 let mut datetime_iso = DateTime::try_new_iso_datetime(1992, 9, 2, 8, 59, 0) .expect("Failed to initialize ISO DateTime instance."); assert_eq!(datetime_iso.date.day_of_week(), IsoWeekday::Wednesday); assert_eq!(datetime_iso.date.year().number, 1992); assert_eq!(datetime_iso.date.month().ordinal, 9); assert_eq!(datetime_iso.date.day_of_month().0, 2); assert_eq!(datetime_iso.time.hour.number(), 8); assert_eq!(datetime_iso.time.minute.number(), 59); assert_eq!(datetime_iso.time.second.number(), 0); assert_eq!(datetime_iso.time.nanosecond.number(), 0); ``` [`ICU4X`]: ../icu/index.html 5876
persian.rs This module contains types and implementations for the Persian calendar. ```rust use icu::calendar::{Date, DateTime}; // `Date` type let persian_date = Date::try_new_persian_date(1348, 10, 11) .expect("Failed to initialize Persian Date instance."); // `DateTime` type let persian_datetime = DateTime::try_new_persian_datetime(1348, 10, 11, 13, 1, 0) .expect("Failed to initialize Persian DateTime instance."); // `Date` checks assert_eq!(persian_date.year().number, 1348); assert_eq!(persian_date.month().ordinal, 10); assert_eq!(persian_date.day_of_month().0, 11); // `DateTime` checks assert_eq!(persian_datetime.date.year().number, 1348); assert_eq!(persian_datetime.date.month().ordinal, 10); assert_eq!(persian_datetime.date.day_of_month().0, 11); assert_eq!(persian_datetime.time.hour.number(), 13); assert_eq!(persian_datetime.time.minute.number(), 1); assert_eq!(persian_datetime.time.second.number(), 0); ``` 27342
provider
provider.rs 🚧 \[Unstable\] Data provider struct definitions for this ICU4X component. <div class="stab unstable"> 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, including in SemVer minor releases. While the serde representation of data structs is guaranteed to be stable, their Rust representation might not be. Use with caution. </div> Read more about data providers: [`icu_provider`] 12332
roc.rs This module contains types and implementations for the Republic of China calendar. ```rust use icu::calendar::{roc::Roc, Date, DateTime}; // `Date` type let date_iso = Date::try_new_iso_date(1970, 1, 2) .expect("Failed to initialize ISO Date instance."); let date_roc = Date::new_from_iso(date_iso, Roc); // `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_roc = DateTime::new_from_iso(datetime_iso, Roc); // `Date` checks assert_eq!(date_roc.year().number, 59); assert_eq!(date_roc.month().ordinal, 1); assert_eq!(date_roc.day_of_month().0, 2); // `DateTime` checks assert_eq!(datetime_roc.date.year().number, 59); assert_eq!(datetime_roc.date.month().ordinal, 1); assert_eq!(datetime_roc.date.day_of_month().0, 2); assert_eq!(datetime_roc.time.hour.number(), 13); assert_eq!(datetime_roc.time.minute.number(), 1); assert_eq!(datetime_roc.time.second.number(), 0); ``` 18077
tests
types.rs This module contains various types used by `icu_calendar` and `icu::datetime` 25304
week_of.rs 27908