pub struct Date<A: AsCalendar> { /* private fields */ }
Expand description

A date for a given calendar

This can work with wrappers around Calendar types, e.g. Rc<C>, via the AsCalendar trait

Implementations

Construct a new Buddhist Date.

Years are specified as BE years.

use icu::calendar::Date;
use std::convert::TryFrom;

let date_buddhist = Date::new_buddhist_date(1970, 1, 2).unwrap();

assert_eq!(date_buddhist.year().number, 1970);
assert_eq!(date_buddhist.month().number, 1);
assert_eq!(date_buddhist.day_of_month().0, 2);

Construct new Coptic Date.

use icu::calendar::Date;

let date_coptic = Date::new_coptic_date(1686, 5, 6).unwrap();

assert_eq!(date_coptic.year().number, 1686);
assert_eq!(date_coptic.month().number, 5);
assert_eq!(date_coptic.day_of_month().0, 6);

Construct a date from an ISO date and some calendar representation

Convert the Date to an ISO Date

Convert the Date to a date in a different calendar

The number of months in the year of this date

The number of days in the year of this date

The number of days in the month of this date

The day of the week for this date

Monday is 1, Sunday is 7, according to ISO

Add a duration to this date, mutating it

Add a duration to this date, returning the new one

Calculating the duration between other - self

The calendar-specific year represented by self

The calendar-specific month represented by self

The calendar-specific day-of-month represented by self

The calendar-specific day-of-month represented by self

Construct a date from raw values for a given calendar. This does not check any invariants for the date and calendar, and should only be called by calendar implementations.

Calling this outside of calendar implementations is sound, but calendar implementations are not expected to do anything sensible with such invalid dates.

AnyCalendar will panic if AnyCalendar Date objects with mismatching date and calendar types are constructed

Get the inner date implementation. Should not be called outside of calendar implementations

Get a reference to the contained calendar

Type-erase the date, converting it to a date for AnyCalendar

Wrap the calendar type in Rc<T>

Useful when paired with Self::to_any() to obtain a Date<Rc<AnyCalendar>>

Construct new Ethiopic Date.

use icu::calendar::Date;

let date_ethiopic = Date::new_ethiopic_date(2014, 8, 25).unwrap();

assert_eq!(date_ethiopic.year().number, 2014);
assert_eq!(date_ethiopic.month().number, 8);
assert_eq!(date_ethiopic.day_of_month().0, 25);

Construct a new Gregorian Date.

Years are specified as ISO years.

use icu::calendar::{Date,
                    iso::IsoYear,
                    iso::IsoMonth,
                    iso::IsoDay};
use std::convert::TryFrom;

let iso_year = IsoYear(1970);
let iso_month = IsoMonth::try_from(1).unwrap();
let iso_day = IsoDay::try_from(2).unwrap();

// Conversion from ISO to Gregorian
let date_gregorian = Date::new_gregorian_date(iso_year, iso_month, iso_day).unwrap();

assert_eq!(date_gregorian.year().number, 1970);
assert_eq!(date_gregorian.month().number, 1);
assert_eq!(date_gregorian.day_of_month().0, 2);

Construct new Indian Date.

use icu::calendar::Date;

let date_indian = Date::new_indian_date(1891, 10, 12).unwrap();

assert_eq!(date_indian.year().number, 1891);
assert_eq!(date_indian.month().number, 10);
assert_eq!(date_indian.day_of_month().0, 12);

Construct a new ISO Date.

use icu::calendar::{Date,
                    iso::IsoYear,
                    iso::IsoMonth,
                    iso::IsoDay};
use std::convert::TryFrom;

let iso_year = IsoYear(1996);
let iso_month = IsoMonth::try_from(2).unwrap();
let iso_day = IsoDay::try_from(3).unwrap();

// Creation of ISO date
let date_iso = Date::new_iso_date(iso_year, iso_month, iso_day).unwrap();

assert_eq!(date_iso.year().number, 1996);
assert_eq!(date_iso.month().number, 2);
assert_eq!(date_iso.day_of_month().0, 3);

Construct a new ISO date from integers.

use icu::calendar::Date;

let date_iso = Date::new_iso_date_from_integers(1970, 1, 2).unwrap();

assert_eq!(date_iso.year().number, 1970);
assert_eq!(date_iso.month().number, 1);
assert_eq!(date_iso.day_of_month().0, 2);

Construct new Julian Date.

use icu::calendar::Date;

let date_julian = Date::new_julian_date(1969, 12, 20).unwrap();

assert_eq!(date_julian.year().number, 1969);
assert_eq!(date_julian.month().number, 12);
assert_eq!(date_julian.day_of_month().0, 20);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.