Skip to content

Commit

Permalink
Format examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Sep 21, 2023
1 parent 88e35c2 commit d2c7048
Show file tree
Hide file tree
Showing 73 changed files with 631 additions and 586 deletions.
24 changes: 15 additions & 9 deletions components/calendar/src/chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
//! This module contains types and implementations for the Chinese calendar.
//!
//! ```rust
//! use icu::calendar::{Ref, Date, DateTime, chinese::Chinese};
//! use icu::calendar::{chinese::Chinese, Date, DateTime, Ref};
//!
//! let chinese = Chinese::new_always_calculating();
//! 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.");
//! 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");
//! 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);
Expand Down Expand Up @@ -330,8 +333,9 @@ impl<A: AsCalendar<Calendar = Chinese>> Date<A> {
///
/// let chinese = Chinese::new_always_calculating();
///
/// let date_chinese = Date::try_new_chinese_date_with_calendar(4660, 6, 11, chinese)
/// .expect("Failed to initialize Chinese Date instance.");
/// let date_chinese =
/// Date::try_new_chinese_date_with_calendar(4660, 6, 11, chinese)
/// .expect("Failed to initialize Chinese Date instance.");
///
/// assert_eq!(date_chinese.year().number, 4660);
/// assert_eq!(date_chinese.year().cyclic.unwrap().get(), 40);
Expand Down Expand Up @@ -366,8 +370,10 @@ impl<A: AsCalendar<Calendar = Chinese>> DateTime<A> {
///
/// let chinese = Chinese::new_always_calculating();
///
/// let chinese_datetime = DateTime::try_new_chinese_datetime_with_calendar(4660, 6, 11, 13, 1, 0, chinese)
/// .expect("Failed to initialize Chinese DateTime instance.");
/// let chinese_datetime = DateTime::try_new_chinese_datetime_with_calendar(
/// 4660, 6, 11, 13, 1, 0, chinese,
/// )
/// .expect("Failed to initialize Chinese DateTime instance.");
///
/// assert_eq!(chinese_datetime.date.year().number, 4660);
/// assert_eq!(chinese_datetime.date.year().related_iso, Some(2023));
Expand Down
5 changes: 3 additions & 2 deletions components/calendar/src/chinese_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
//! as well as in related and derived calendars such as the Korean and Vietnamese lunar calendars.
//!
//! ```rust
//! use icu::calendar::{chinese::Chinese, Iso, Date};
//! 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_always_calculating());
//! let chinese_date =
//! Date::new_from_iso(iso_date, Chinese::new_always_calculating());
//!
//! assert_eq!(chinese_date.year().number, 4660);
//! assert_eq!(chinese_date.year().related_iso, Some(2023));
Expand Down
20 changes: 12 additions & 8 deletions components/calendar/src/dangi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! This module contains types and implementations for the Korean Dangi calendar.
//!
//! ```rust
//! use icu::calendar::{Ref, Date, DateTime};
//! use icu::calendar::dangi::Dangi;
//! use icu::calendar::{Date, DateTime, Ref};
//!
//! let dangi = Dangi::new_always_calculating();
//! let dangi = Ref(&dangi); // to avoid cloning
Expand All @@ -16,8 +16,10 @@
//! .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.");
//! 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);
Expand Down Expand Up @@ -64,7 +66,7 @@ use tinystr::tinystr;
/// going to be perfect.
///
/// ```rust
/// use icu::calendar::{Date, dangi::Dangi, chinese::Chinese};
/// use icu::calendar::{chinese::Chinese, dangi::Dangi, Date};
/// use tinystr::tinystr;
///
/// let iso_a = Date::try_new_iso_date(2012, 4, 23).unwrap();
Expand Down Expand Up @@ -300,8 +302,8 @@ impl<A: AsCalendar<Calendar = Dangi>> Date<A> {
/// one that loads such data from a provider will be added in the future (#3933)
///
/// ```rust
/// use icu::calendar::Date;
/// use icu::calendar::dangi::Dangi;
/// use icu::calendar::Date;
///
/// let dangi = Dangi::new_always_calculating();
///
Expand Down Expand Up @@ -336,13 +338,15 @@ impl<A: AsCalendar<Calendar = Dangi>> DateTime<A> {
/// one that loads such data from a provider will be added in the future (#3933)
///
/// ```rust
/// use icu::calendar::DateTime;
/// use icu::calendar::dangi::Dangi;
/// use icu::calendar::DateTime;
///
/// let dangi = Dangi::new_always_calculating();
///
/// let dangi_datetime = DateTime::try_new_dangi_datetime_with_calendar(4356, 6, 6, 13, 1, 0, dangi)
/// .expect("Failed to initialize Dangi DateTime instance.");
/// let dangi_datetime = DateTime::try_new_dangi_datetime_with_calendar(
/// 4356, 6, 6, 13, 1, 0, dangi,
/// )
/// .expect("Failed to initialize Dangi DateTime instance.");
///
/// assert_eq!(dangi_datetime.date.year().number, 4356);
/// assert_eq!(dangi_datetime.date.year().related_iso, Some(2023));
Expand Down
28 changes: 17 additions & 11 deletions components/calendar/src/hebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
//! This module contains types and implementations for the Hebrew calendar.
//!
//! ```rust
//! use icu::calendar::{Ref, Date, DateTime, hebrew::Hebrew};
//! use icu::calendar::{hebrew::Hebrew, Date, DateTime, Ref};
//!
//! let hebrew = Hebrew::new_always_calculating();
//! let hebrew = Ref(&hebrew); // to avoid cloning
//!
//! // `Date` type
//! let hebrew_date = Date::try_new_hebrew_date_with_calendar(3425, 10, 11, hebrew)
//! .expect("Failed to initialize hebrew Date instance.");
//! let hebrew_date =
//! Date::try_new_hebrew_date_with_calendar(3425, 10, 11, hebrew)
//! .expect("Failed to initialize hebrew Date instance.");
//!
//! // `DateTime` type
//! let hebrew_datetime = DateTime::try_new_hebrew_datetime_with_calendar(3425, 10, 11, 13, 1, 0, hebrew)
//! .expect("Failed to initialize hebrew DateTime instance.");
//! let hebrew_datetime = DateTime::try_new_hebrew_datetime_with_calendar(
//! 3425, 10, 11, 13, 1, 0, hebrew,
//! )
//! .expect("Failed to initialize hebrew DateTime instance.");
//!
//! // `Date` checks
//! assert_eq!(hebrew_date.year().number, 3425);
Expand Down Expand Up @@ -347,13 +350,14 @@ impl<A: AsCalendar<Calendar = Hebrew>> Date<A> {
///
///
/// ```rust
/// use icu::calendar::Date;
/// use icu::calendar::hebrew::Hebrew;
/// use icu::calendar::Date;
///
/// let hebrew = Hebrew::new_always_calculating();
///
/// let date_hebrew = Date::try_new_hebrew_date_with_calendar(3425, 4, 25, hebrew)
/// .expect("Failed to initialize Hebrew Date instance.");
/// let date_hebrew =
/// Date::try_new_hebrew_date_with_calendar(3425, 4, 25, hebrew)
/// .expect("Failed to initialize Hebrew Date instance.");
///
/// assert_eq!(date_hebrew.year().number, 3425);
/// assert_eq!(date_hebrew.month().ordinal, 4);
Expand All @@ -378,13 +382,15 @@ impl<A: AsCalendar<Calendar = Hebrew>> DateTime<A> {
/// one that loads such data from a provider will be added in the future (#3933)
///
/// ```rust
/// use icu::calendar::DateTime;
/// use icu::calendar::hebrew::Hebrew;
/// use icu::calendar::DateTime;
///
/// let hebrew = Hebrew::new_always_calculating();
///
/// let datetime_hebrew = DateTime::try_new_hebrew_datetime_with_calendar(4201, 10, 11, 13, 1, 0, hebrew)
/// .expect("Failed to initialize Hebrew DateTime instance");
/// let datetime_hebrew = DateTime::try_new_hebrew_datetime_with_calendar(
/// 4201, 10, 11, 13, 1, 0, hebrew,
/// )
/// .expect("Failed to initialize Hebrew DateTime instance");
///
/// assert_eq!(datetime_hebrew.date.year().number, 4201);
/// assert_eq!(datetime_hebrew.date.month().ordinal, 10);
Expand Down
65 changes: 40 additions & 25 deletions components/calendar/src/islamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
//! This module contains types and implementations for the Islamic calendars.
//!
//! ```rust
//! use icu::calendar::{Date, DateTime, Ref};
//! 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.");
//! 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.");
//! 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);
Expand Down Expand Up @@ -302,13 +305,14 @@ impl<A: AsCalendar<Calendar = IslamicObservational>> Date<A> {
/// Has no negative years, only era is the AH.
///
/// ```rust
/// use icu::calendar::Date;
/// use icu::calendar::islamic::IslamicObservational;
/// use icu::calendar::Date;
///
/// let islamic = IslamicObservational::new_always_calculating();
///
/// let date_islamic = Date::try_new_observational_islamic_date(1392, 4, 25, islamic)
/// .expect("Failed to initialize Islamic Date instance.");
/// let date_islamic =
/// Date::try_new_observational_islamic_date(1392, 4, 25, islamic)
/// .expect("Failed to initialize Islamic Date instance.");
///
/// assert_eq!(date_islamic.year().number, 1392);
/// assert_eq!(date_islamic.month().ordinal, 4);
Expand All @@ -330,13 +334,15 @@ impl<A: AsCalendar<Calendar = IslamicObservational>> DateTime<A> {
/// Construct a new Islamic Observational datetime from integers.
///
/// ```rust
/// use icu::calendar::DateTime;
/// use icu::calendar::islamic::IslamicObservational;
/// use icu::calendar::DateTime;
///
/// let islamic = IslamicObservational::new_always_calculating();
///
/// let datetime_islamic = DateTime::try_new_observational_islamic_datetime(474, 10, 11, 13, 1, 0, islamic)
/// .expect("Failed to initialize Islamic DateTime instance.");
/// let datetime_islamic = DateTime::try_new_observational_islamic_datetime(
/// 474, 10, 11, 13, 1, 0, islamic,
/// )
/// .expect("Failed to initialize Islamic DateTime instance.");
///
/// assert_eq!(datetime_islamic.date.year().number, 474);
/// assert_eq!(datetime_islamic.date.month().ordinal, 10);
Expand Down Expand Up @@ -489,8 +495,8 @@ impl<A: AsCalendar<Calendar = IslamicUmmAlQura>> Date<A> {
/// Has no negative years, only era is the AH.
///
/// ```rust
/// use icu::calendar::Date;
/// use icu::calendar::islamic::IslamicUmmAlQura;
/// use icu::calendar::Date;
///
/// let islamic = IslamicUmmAlQura::new_always_calculating();
///
Expand All @@ -517,13 +523,14 @@ impl<A: AsCalendar<Calendar = IslamicUmmAlQura>> DateTime<A> {
/// Construct a new Islamic Umm al-Qura datetime from integers.
///
/// ```rust
/// use icu::calendar::DateTime;
/// use icu::calendar::islamic::IslamicUmmAlQura;
/// use icu::calendar::DateTime;
///
/// let islamic = IslamicUmmAlQura::new_always_calculating();
///
/// let datetime_islamic = DateTime::try_new_ummalqura_datetime(474, 10, 11, 13, 1, 0, islamic)
/// .expect("Failed to initialize Islamic DateTime instance.");
/// let datetime_islamic =
/// DateTime::try_new_ummalqura_datetime(474, 10, 11, 13, 1, 0, islamic)
/// .expect("Failed to initialize Islamic DateTime instance.");
///
/// assert_eq!(datetime_islamic.date.year().number, 474);
/// assert_eq!(datetime_islamic.date.month().ordinal, 10);
Expand Down Expand Up @@ -762,13 +769,14 @@ impl<A: AsCalendar<Calendar = IslamicCivil>> Date<A> {
/// Has no negative years, only era is the AH.
///
/// ```rust
/// use icu::calendar::Date;
/// use icu::calendar::islamic::IslamicCivil;
/// use icu::calendar::Date;
///
/// let islamic = IslamicCivil::new_always_calculating();
///
/// let date_islamic = Date::try_new_islamic_civil_date_with_calendar(1392, 4, 25, islamic)
/// .expect("Failed to initialize Islamic Date instance.");
/// let date_islamic =
/// Date::try_new_islamic_civil_date_with_calendar(1392, 4, 25, islamic)
/// .expect("Failed to initialize Islamic Date instance.");
///
/// assert_eq!(date_islamic.year().number, 1392);
/// assert_eq!(date_islamic.month().ordinal, 4);
Expand All @@ -790,12 +798,15 @@ impl<A: AsCalendar<Calendar = IslamicCivil>> DateTime<A> {
/// Construct a new Civil Islamic datetime from integers.
///
/// ```rust
/// use icu::calendar::DateTime;
/// use icu::calendar::islamic::IslamicCivil;
/// use icu::calendar::DateTime;
///
/// let islamic = IslamicCivil::new_always_calculating();
///
/// let datetime_islamic = DateTime::try_new_islamic_civil_datetime_with_calendar(474, 10, 11, 13, 1, 0, islamic)
/// let datetime_islamic =
/// DateTime::try_new_islamic_civil_datetime_with_calendar(
/// 474, 10, 11, 13, 1, 0, islamic,
/// )
/// .expect("Failed to initialize Islamic DateTime instance.");
///
/// assert_eq!(datetime_islamic.date.year().number, 474);
Expand Down Expand Up @@ -998,13 +1009,14 @@ impl<A: AsCalendar<Calendar = IslamicTabular>> Date<A> {
/// Has no negative years, only era is the AH.
///
/// ```rust
/// use icu::calendar::Date;
/// use icu::calendar::islamic::IslamicTabular;
/// use icu::calendar::Date;
///
/// let islamic = IslamicTabular::new_always_calculating();
///
/// let date_islamic = Date::try_new_islamic_tabular_date_with_calendar(1392, 4, 25, islamic)
/// .expect("Failed to initialize Islamic Date instance.");
/// let date_islamic =
/// Date::try_new_islamic_tabular_date_with_calendar(1392, 4, 25, islamic)
/// .expect("Failed to initialize Islamic Date instance.");
///
/// assert_eq!(date_islamic.year().number, 1392);
/// assert_eq!(date_islamic.month().ordinal, 4);
Expand All @@ -1026,12 +1038,15 @@ impl<A: AsCalendar<Calendar = IslamicTabular>> DateTime<A> {
/// Construct a new Tabular Islamic datetime from integers.
///
/// ```rust
/// use icu::calendar::DateTime;
/// use icu::calendar::islamic::IslamicTabular;
/// use icu::calendar::DateTime;
///
/// let islamic = IslamicTabular::new_always_calculating();
///
/// let datetime_islamic = DateTime::try_new_islamic_tabular_datetime_with_calendar(474, 10, 11, 13, 1, 0, islamic)
/// let datetime_islamic =
/// DateTime::try_new_islamic_tabular_datetime_with_calendar(
/// 474, 10, 11, 13, 1, 0, islamic,
/// )
/// .expect("Failed to initialize Islamic DateTime instance.");
///
/// assert_eq!(datetime_islamic.date.year().number, 474);
Expand Down
10 changes: 6 additions & 4 deletions components/calendar/src/persian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
//! .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.");
//! 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);
Expand Down Expand Up @@ -265,8 +266,9 @@ impl DateTime<Persian> {
/// ```rust
/// use icu::calendar::DateTime;
///
/// let datetime_persian = DateTime::try_new_persian_datetime(474, 10, 11, 13, 1, 0)
/// .expect("Failed to initialize Persian DateTime instance.");
/// let datetime_persian =
/// DateTime::try_new_persian_datetime(474, 10, 11, 13, 1, 0)
/// .expect("Failed to initialize Persian DateTime instance.");
///
/// assert_eq!(datetime_persian.date.year().number, 474);
/// assert_eq!(datetime_persian.date.month().ordinal, 10);
Expand Down
Loading

0 comments on commit d2c7048

Please sign in to comment.