Skip to content

Commit

Permalink
Merge branch 'main' into i/1791/calendar-benches
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpollack committed May 20, 2022
2 parents 7b8ecd1 + 8fc8f5c commit e24613f
Show file tree
Hide file tree
Showing 288 changed files with 550,455 additions and 1,828 deletions.
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ components/uniset/ @echeran @iainireland
experimental/bies/ @sffc
experimental/calendar/ @Manishearth @sffc
experimental/codepointtrie/ @echeran
experimental/collator/ @hsivonen @echeran
experimental/normalizer/ @hsivonen @echeran
experimental/provider_ppucd/ @echeran
experimental/segmenter/ @aethanyc @makotokato
experimental/segmenter_lstm/ @aethanyc @sffc
Expand Down
63 changes: 63 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ members = [
"experimental/char16trie",
"experimental/crabbake",
"experimental/crabbake/derive",
"experimental/collator",
"experimental/normalizer",
"experimental/segmenter",
"experimental/segmenter_lstm",
"ffi/capi_cdylib",
Expand Down
24 changes: 7 additions & 17 deletions components/calendar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ for working with dates, encompassing information about the day, month, year,
as well as the calendar type.

```rust
use icu_calendar::{Date,
DateDuration,
DateDurationUnit,
types::IsoWeekday};
use icu_calendar::{types::IsoWeekday, Date, DateDuration, DateDurationUnit};

// Creating ISO date: 1992-09-02.
let mut date_iso = Date::new_iso_date_from_integers(1992, 9, 2)
Expand Down Expand Up @@ -72,9 +69,7 @@ assert_eq!(mutated_date_iso.day_of_month().0, 27);
Example of converting an ISO date across Indian and Buddhist calendars.

```rust
use icu_calendar::{Date,
buddhist::Buddhist,
indian::Indian};
use icu_calendar::{buddhist::Buddhist, indian::Indian, Date};

// Creating ISO date: 1992-09-02.
let mut date_iso = Date::new_iso_date_from_integers(1992, 9, 2)
Expand Down Expand Up @@ -103,14 +98,10 @@ year, and calendar type. Additionally, `DateTime` objects contain an accessible
`Time` object, including granularity of hour, minute, second, and nanosecond.

```rust
use icu_calendar::{DateTime,
DateDuration,
types::IsoWeekday,
types::IsoHour,
types::IsoMinute,
types::IsoSecond,
types::NanoSecond,
types::Time};
use icu_calendar::{
types::IsoHour, types::IsoMinute, types::IsoSecond, types::IsoWeekday, types::NanoSecond,
types::Time, DateDuration, DateTime,
};

// Creating ISO date: 1992-09-02 8:59
let mut datetime_iso = DateTime::new_iso_datetime_from_integers(1992, 9, 2, 8, 59, 0)
Expand All @@ -128,8 +119,7 @@ assert_eq!(datetime_iso.time.nanosecond, NanoSecond::new_unchecked(0));
// Advancing date by 1 year, 2 months, 3 weeks, 4 days.
datetime_iso.date.add(DateDuration::new(1, 2, 3, 4));
// New time of 14:30
datetime_iso.time = Time::try_new(14, 30, 0, 0)
.expect("Failed to initialize Time instance.");
datetime_iso.time = Time::try_new(14, 30, 0, 0).expect("Failed to initialize Time instance.");

assert_eq!(datetime_iso.date.year().number, 1993);
assert_eq!(datetime_iso.date.month().number, 11);
Expand Down
15 changes: 6 additions & 9 deletions components/calendar/src/buddhist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//! This module contains types and implementations for the Buddhist calendar.
//!
//! ```rust
//! use icu::calendar::{Date, DateTime,
//! types::IsoHour, types::IsoMinute, types::IsoSecond,
//! buddhist::Buddhist};
//! use icu::calendar::{
//! buddhist::Buddhist, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime,
//! };
//!
//! // `Date` type
//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2)
Expand Down Expand Up @@ -133,8 +133,8 @@ impl Date<Buddhist> {
/// use icu::calendar::Date;
/// use std::convert::TryFrom;
///
/// let date_buddhist = Date::new_buddhist_date(1970, 1, 2)
/// .expect("Failed to initialize Buddhist Date instance.");
/// let date_buddhist =
/// Date::new_buddhist_date(1970, 1, 2).expect("Failed to initialize Buddhist Date instance.");
///
/// assert_eq!(date_buddhist.year().number, 1970);
/// assert_eq!(date_buddhist.month().number, 1);
Expand All @@ -156,10 +156,7 @@ impl DateTime<Buddhist> {
/// Years are specified as BE years.
///
/// ```rust
/// use icu::calendar::{DateTime,
/// types::IsoHour,
/// types::IsoMinute,
/// types::IsoSecond};
/// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime};
///
/// let datetime_buddhist = DateTime::new_buddhist_datetime(1970, 1, 2, 13, 1, 0)
/// .expect("Failed to initialize Buddhist DateTime instance.");
Expand Down
15 changes: 6 additions & 9 deletions components/calendar/src/coptic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//! This module contains types and implementations for the Coptic calendar.
//!
//! ```rust
//! use icu::calendar::{Date, DateTime,
//! types::IsoHour, types::IsoMinute, types::IsoSecond,
//! coptic::Coptic};
//! use icu::calendar::{
//! coptic::Coptic, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime,
//! };
//!
//! // `Date` type
//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2)
Expand Down Expand Up @@ -204,8 +204,8 @@ impl Date<Coptic> {
/// ```rust
/// use icu::calendar::Date;
///
/// let date_coptic = Date::new_coptic_date(1686, 5, 6)
/// .expect("Failed to initialize Coptic Date instance.");
/// let date_coptic =
/// Date::new_coptic_date(1686, 5, 6).expect("Failed to initialize Coptic Date instance.");
///
/// assert_eq!(date_coptic.year().number, 1686);
/// assert_eq!(date_coptic.month().number, 5);
Expand All @@ -232,10 +232,7 @@ impl DateTime<Coptic> {
/// Construct a new Coptic datetime from integers.
///
/// ```rust
/// use icu::calendar::{DateTime,
/// types::IsoHour,
/// types::IsoMinute,
/// types::IsoSecond};
/// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime};
///
/// let datetime_coptic = DateTime::new_coptic_datetime(1686, 5, 6, 13, 1, 0)
/// .expect("Failed to initialize Coptic DateTime instance.");
Expand Down
16 changes: 14 additions & 2 deletions components/calendar/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,22 @@ impl<C: Calendar> AsCalendar for Rc<C> {
}
}

/// A date for a given calendar
/// A date for a given calendar.
///
/// This can work with wrappers around [`Calendar`] types,
/// e.g. `Rc<C>`, via the [`AsCalendar`] trait
/// e.g. `Rc<C>`, via the [`AsCalendar`] trait.
///
/// ```rust
/// use icu::calendar::Date;
///
/// // Example: creation of ISO date from integers.
/// let date_iso = Date::new_iso_date_from_integers(1970, 1, 2)
/// .expect("Failed to initialize ISO Date instance.");
///
/// assert_eq!(date_iso.year().number, 1970);
/// assert_eq!(date_iso.month().number, 1);
/// assert_eq!(date_iso.day_of_month().0, 2);
/// ```
pub struct Date<A: AsCalendar> {
pub(crate) inner: <A::Calendar as Calendar>::DateInner,
calendar: A,
Expand Down
21 changes: 18 additions & 3 deletions components/calendar/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@
use crate::types::Time;
use crate::{AsCalendar, Date, Iso};

/// A date+time for a given calendar
/// A date+time for a given calendar.
///
/// This can work with wrappers arount [`Calendar`](crate::Calendar) types,
/// This can work with wrappers around [`Calendar`](crate::Calendar) types,
/// e.g. `Rc<C>`, via the [`AsCalendar`] trait, much like
/// [`Date`]
/// [`Date`].
///
/// ```rust
/// use icu::calendar::{DateTime, types::IsoHour, types::IsoMinute, types::IsoSecond};
///
/// // Example: Construction of ISO datetime from integers.
/// let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0)
/// .expect("Failed to initialize ISO DateTime instance.");
///
/// assert_eq!(datetime_iso.date.year().number, 1970);
/// assert_eq!(datetime_iso.date.month().number, 1);
/// assert_eq!(datetime_iso.date.day_of_month().0, 2);
/// assert_eq!(datetime_iso.time.hour, IsoHour::new_unchecked(13));
/// assert_eq!(datetime_iso.time.minute, IsoMinute::new_unchecked(1));
/// assert_eq!(datetime_iso.time.second, IsoSecond::new_unchecked(0));
/// ```
#[derive(Debug)]
#[allow(clippy::exhaustive_structs)] // this type is stable
pub struct DateTime<A: AsCalendar> {
Expand Down
15 changes: 6 additions & 9 deletions components/calendar/src/ethiopic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//! This module contains types and implementations for the Ethiopic calendar.
//!
//! ```rust
//! use icu::calendar::{Date, DateTime,
//! types::IsoHour, types::IsoMinute, types::IsoSecond,
//! ethiopic::Ethiopic};
//! use icu::calendar::{
//! ethiopic::Ethiopic, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime,
//! };
//!
//! // `Date` type
//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2)
Expand Down Expand Up @@ -218,8 +218,8 @@ impl Date<Ethiopic> {
/// ```rust
/// use icu::calendar::Date;
///
/// let date_ethiopic = Date::new_ethiopic_date(2014, 8, 25)
/// .expect("Failed to initialize Ethopic Date instance.");
/// let date_ethiopic =
/// Date::new_ethiopic_date(2014, 8, 25).expect("Failed to initialize Ethopic Date instance.");
///
/// assert_eq!(date_ethiopic.year().number, 2014);
/// assert_eq!(date_ethiopic.month().number, 8);
Expand Down Expand Up @@ -254,10 +254,7 @@ impl DateTime<Ethiopic> {
/// Construct a new Ethiopic datetime from integers.
///
/// ```rust
/// use icu::calendar::{DateTime,
/// types::IsoHour,
/// types::IsoMinute,
/// types::IsoSecond};
/// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime};
///
/// let datetime_ethiopic = DateTime::new_ethiopic_datetime(2014, 8, 25, 13, 1, 0)
/// .expect("Failed to initialize Ethiopic DateTime instance.");
Expand Down
22 changes: 7 additions & 15 deletions components/calendar/src/gregorian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//! This module contains types and implementations for the Gregorian calendar.
//!
//! ```rust
//! use icu::calendar::{Date, DateTime,
//! types::IsoHour, types::IsoMinute, types::IsoSecond,
//! gregorian::Gregorian};
//! use icu::calendar::{
//! gregorian::Gregorian, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime,
//! };
//!
//! // `Date` type
//! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2)
Expand Down Expand Up @@ -125,17 +125,12 @@ impl Date<Gregorian> {
/// Years are specified as ISO years.
///
/// ```rust
/// use icu::calendar::{Date,
/// iso::IsoYear,
/// iso::IsoMonth,
/// iso::IsoDay};
/// use icu::calendar::{iso::IsoDay, iso::IsoMonth, iso::IsoYear, Date};
/// use std::convert::TryFrom;
///
/// let iso_year = IsoYear(1970);
/// let iso_month = IsoMonth::try_from(1)
/// .expect("Failed to initialize IsoMonth instance.");
/// let iso_day = IsoDay::try_from(2)
/// .expect("Failed to initialize IsoDay instance.");
/// let iso_month = IsoMonth::try_from(1).expect("Failed to initialize IsoMonth instance.");
/// let iso_day = IsoDay::try_from(2).expect("Failed to initialize IsoDay instance.");
///
/// // Conversion from ISO to Gregorian
/// let date_gregorian = Date::new_gregorian_date(iso_year, iso_month, iso_day)
Expand All @@ -160,10 +155,7 @@ impl DateTime<Gregorian> {
/// Years are specified as ISO years.
///
/// ```rust
/// use icu::calendar::{DateTime,
/// types::IsoHour,
/// types::IsoMinute,
/// types::IsoSecond};
/// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime};
///
/// let datetime_gregorian = DateTime::new_gregorian_datetime(1970, 1, 2, 13, 1, 0)
/// .expect("Failed to initialize Gregorian DateTime instance.");
Expand Down
Loading

0 comments on commit e24613f

Please sign in to comment.