Gregorian

Struct Gregorian 

Source
pub struct Gregorian;
Expand description

The Gregorian Calendar

The Gregorian calendar is an improvement over the Julian calendar. It was adopted under Pope Gregory XIII in 1582 CE by much of Roman Catholic Europe, and over the following centuries by all other countries that had been using the Julian calendar. Eventually even countries that had been using other calendars adopted this calendar, and today it is used as the international civil calendar.

This implementation extends proleptically for dates before the calendar’s creation.

This corresponds to the "gregory" CLDR calendar.

§Era codes

This calendar uses two era codes: bce (alias bc), and ce (alias ad), corresponding to the BCE and CE eras.

§Months and days

The 12 months are called January (M01, 31 days), February (M02, 28 days), March (M03, 31 days), April (M04, 30 days), May (M05, 31 days), June (M06, 30 days), July (M07, 31 days), August (M08, 31 days), September (M09, 30 days), October (M10, 31 days), November (M11, 30 days), December (M12, 31 days).

In leap years (years divisible by 4 but not 100 except when divisble by 400), February gains a 29th day.

Standard years thus have 365 days, and leap years 366.

§Calendar drift

The Gregorian calendar has an average year length of 365.2425, slightly longer than the mean solar year, so this calendar drifts 1 day in ~7700 years with respect to the seasons.

§Historical accuracy

This type implements the proleptic Gregorian calendar, with dates before 1582 CE using the rules projected backwards. Care needs to be taken when intepreting historical dates before or during the transition from the Julian to the Gregorian calendar. Some regions continued using the Julian calendar as late as the 20th century. Sources often mark dates as “New Style” (Gregorian) or “Old Style” (Julian) if there is ambiguity.

Historically, the Julian/Gregorian calendars were used with a variety of year reckoning schemes (see Julian for more detail). The Gregorian calendar has generally been used with the Anno Domini/Common era since its inception. However, some countries that have adopted the Gregorian calendar more recently are still using their traditional year-reckoning schemes. This crate implements some of these as different types, i.e the Thai Buddhist calendar, the Japanese calendar, and the Chinese Republican Calendar (Roc).

Implementations§

Source§

impl Gregorian

Source

pub fn easter(year: i32) -> Date<Gregorian>

Returns the date of Easter in the given year.

Trait Implementations§

Source§

impl Calendar for Gregorian

Source§

type DateInner = GregorianDateInner

The internal type used to represent dates Read more
Source§

type Year = EraYear

The type of YearInfo returned by the date
Source§

type DifferenceError = Infallible

The type of error returned by until
Source§

fn from_codes( &self, era: Option<&str>, year: i32, month_code: MonthCode, day: u8, ) -> Result<<Gregorian as Calendar>::DateInner, DateError>

Construct a date from era/month codes and fields Read more
Source§

fn from_rata_die(&self, rd: RataDie) -> <Gregorian as Calendar>::DateInner

Construct the date from a RataDie
Source§

fn to_rata_die(&self, date: &<Gregorian as Calendar>::DateInner) -> RataDie

Obtain a RataDie from this date
Source§

fn has_cheap_iso_conversion(&self) -> bool

Whether from_iso/to_iso is more efficient than from_rata_die/to_rata_die.
Source§

fn from_iso(&self, iso: IsoDateInner) -> <Gregorian as Calendar>::DateInner

Construct the date from an ISO date. Read more
Source§

fn to_iso(&self, date: &<Gregorian as Calendar>::DateInner) -> IsoDateInner

Obtain an ISO date from this date. Read more
Source§

fn months_in_year(&self, date: &<Gregorian as Calendar>::DateInner) -> u8

Count the number of months in a given year, specified by providing a date from that year
Source§

fn days_in_year(&self, date: &<Gregorian as Calendar>::DateInner) -> u16

Count the number of days in a given year, specified by providing a date from that year
Source§

fn days_in_month(&self, date: &<Gregorian as Calendar>::DateInner) -> u8

Count the number of days in a given month, specified by providing a date from that year/month
Source§

fn year_info( &self, date: &<Gregorian as Calendar>::DateInner, ) -> <Gregorian as Calendar>::Year

Information about the year
Source§

fn is_in_leap_year(&self, date: &<Gregorian as Calendar>::DateInner) -> bool

Calculate if a date is in a leap year
Source§

fn month(&self, date: &<Gregorian as Calendar>::DateInner) -> MonthInfo

The calendar-specific month represented by date
Source§

fn day_of_month(&self, date: &<Gregorian as Calendar>::DateInner) -> DayOfMonth

The calendar-specific day-of-month represented by date
Source§

fn day_of_year(&self, date: &<Gregorian as Calendar>::DateInner) -> DayOfYear

Information of the day of the year
Source§

fn debug_name(&self) -> &'static str

Obtain a name for the calendar for debug printing
Source§

fn calendar_algorithm(&self) -> Option<CalendarAlgorithm>

Returns the CalendarAlgorithm that is required to match when parsing into this calendar. Read more
Source§

fn extended_year(&self, date: &Self::DateInner) -> i32

Source§

impl CldrCalendar for Gregorian

Source§

type YearNamesV1 = DatetimeNamesYearGregorianV1

The data marker for loading year symbols for this calendar.
Source§

type MonthNamesV1 = DatetimeNamesMonthGregorianV1

The data marker for loading month symbols for this calendar.
Source§

type SkeletaV1 = DatetimePatternsDateGregorianV1

The data marker for loading skeleton patterns for this calendar.
Source§

impl Clone for Gregorian

Source§

fn clone(&self) -> Gregorian

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Gregorian

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Gregorian

Source§

fn default() -> Gregorian

Returns the “default value” for a type. Read more
Source§

impl From<Gregorian> for AnyCalendar

Source§

fn from(value: Gregorian) -> AnyCalendar

Converts to this type from the input type.
Source§

impl IntoAnyCalendar for Gregorian

Source§

fn to_any(self) -> AnyCalendar

Convert this calendar into an AnyCalendar, moving it Read more
Source§

fn kind(&self) -> AnyCalendarKind

The AnyCalendarKind enum variant associated with this calendar
Source§

fn from_any(any: AnyCalendar) -> Result<Gregorian, AnyCalendar>

Move an AnyCalendar into a Self, or returning it as an error if the types do not match. Read more
Source§

fn from_any_ref(any: &AnyCalendar) -> Option<&Gregorian>

Convert an AnyCalendar reference into a Self reference. Read more
Source§

fn date_to_any(&self, d: &<Gregorian as Calendar>::DateInner) -> AnyDateInner

Convert a date for this calendar into an AnyDateInner Read more
Source§

impl Copy for Gregorian

Source§

impl IntoFormattableAnyCalendar for Gregorian

Source§

impl UnstableSealed for Gregorian

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<C> AsCalendar for C
where C: Calendar,

Source§

type Calendar = C

The calendar being wrapped
Source§

fn as_calendar(&self) -> &C

Obtain the inner calendar
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> GetField<T> for T
where T: Copy + UnstableSealed,

Source§

fn get_field(&self) -> T

Returns the value of this trait’s field T.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,