Struct GregorianDate

Source
pub struct GregorianDate { /* private fields */ }
Expand description

Gregorian Calendar date (proleptic).

The implementation for the Gregorian Calendar is very slim and intentionally doesn’t have a dedicated month type or support weekdays. It’s only here to allow conversions from the Gregorian Calendar to SAC13 and vice-versa. If you want better typing for the Gregorian Calender check out the crates chrono and time.

§BC years

This proleptic Gregorian Calendar implementation uses astronomical year numbering, which means that zero and negative years to represent BC years.

  • 0 => 1 BC
  • -1 => 2 BC
  • -2 => 3 BC
  • etc.

Implementations§

Source§

impl GregorianDate

Source

pub const MIN: Self

Earliest representable date: -10’000-03-22

Corresponds to A000-01-01 in SAC13. We only allow GregorianDates that have a corresponding SAC13 date to simplify the API.

Source

pub const MAX: Self

Latest representable date: 16’000-03-17

Corresponds to Z999-13-29 in SAC13. We only allow GregorianDates that have a corresponding SAC13 date to simplify the API.

Source

pub fn parse_str(input: &str) -> Option<ParsedGregorianDate>

Tries to parse a Gregorian Calendar date.

For details about the supported formats see SacOrGreg::parse_str.

Source

pub const fn from_ymd(year: i16, month: u8, day: u8) -> Option<Self>

Creates a Gregorian Calendar date from its components year, month and day.

Returns None if the given date is invalid (doesn’t exist in the Gregorian Calendar), like day zero or August 32th, or February 29th on non-leap (common) years.

It also returns None if the date is outside the supported SAC13 range (see GregorianDate::MIN and GregorianDate::MAX).

Source

pub const fn is_leap_year(year: i16) -> bool

Returns true if the given year is a leap year in the proleptic Gregorian Calendar.

The current implementation also covers years outside the range GregorianDate::MIN - GregorianDate::MAX but don’t rely on that because this might change without a major version bump.

Source

pub const fn month_len(year: i16, month: u8) -> Option<u8>

Determines the length of a month in days for a given year and month pair.

Returns None for invalid combinations (like the months > 12).

The current implementation also covers years outside the range GregorianDate::MIN - GregorianDate::MAX but don’t rely in that because this might change without a major version bump.

Source

pub const fn year(&self) -> i16

The year component of the date. For limits see GregorianDate::MIN and GregorianDate::MAX.

Source

pub const fn month(&self) -> u8

The month component of the date. Values: 1 (Junary) - 12 (December).

Source

pub const fn day(&self) -> u8

The day component of the date. Values: 1 - 31.

Trait Implementations§

Source§

impl CalendarDate for GregorianDate

Source§

const MIN: Self = Self::MIN

Earliest representable date.
Source§

const MAX: Self = Self::MAX

Latest representable date.
Source§

fn as_julian(&self) -> i32

Convert the date into the corresponding Julian Day Number.
Source§

fn from_julian(value: i32) -> Option<Self>

Get the date from the corresponding Julian
Source§

fn tomorrow(self) -> Option<Self>

Gets the next date.
Source§

fn yesterday(self) -> Option<Self>

Gets the previous date.
Source§

fn convert<T: CalendarDate>(self) -> T

Converts the calendar date to a different calendar system. Read more
Source§

impl Clone for GregorianDate

Source§

fn clone(&self) -> GregorianDate

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 GregorianDate

Source§

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

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

impl Display for GregorianDate

Source§

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

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

impl Hash for GregorianDate

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for GregorianDate

Source§

fn cmp(&self, other: &GregorianDate) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for GregorianDate

Source§

fn eq(&self, other: &GregorianDate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for GregorianDate

Source§

fn partial_cmp(&self, other: &GregorianDate) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for GregorianDate

Source§

impl Eq for GregorianDate

Source§

impl StructuralPartialEq for GregorianDate

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<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, 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, 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.