GregorianDate

Struct GregorianDate 

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

Representation of a proleptic Gregorian date. Only represents logic down to single-day accuracy: i.e., leap days are included, but leap seconds are not. This is useful in keeping this calendar applicable to all different time scales. Can represent years from -2^31 up to 2^31 - 1.

This is the calendar effectively used by the hifitime and chrono libraries.

Implementations§

Source§

impl GregorianDate

Source

pub const fn new( year: i32, month: Month, day: u8, ) -> Result<Self, InvalidGregorianDate>

Creates a new Gregorian date, given its year, month, and day. If the date is not a valid proleptic Gregorian date, returns a GregorianDateDoesNotExist to indicate that the requested date does not exist in the proleptic Gregorian calendar.

This function will never panic.

Source

pub const fn from_date(date: Date) -> Self

Constructs a Gregorian date from a given Date instance. Useful primarily when an existing Date must be printed in human-readable format.

Uses Howard Hinnant’s civil_from_days algorithm.

Source

pub const fn into_date(&self) -> Date

Constructs a Date from a given Gregorian date. Uses Howard Hinnant’s days_from_civil algorithm.

Source

pub const fn from_ordinal_date( year: i32, day_of_year: u16, ) -> Result<Self, InvalidDayOfYear>

Creates a new date given only the year and the day-of-year. Implementation is based on an algorithm found by A. Pouplier and reported by Jean Meeus in Astronomical Algorithms.

This function will never panic.

Source

pub const fn year(&self) -> i32

Returns the year stored inside this proleptic Gregorian date. Astronomical year numbering is used (as also done in NAIF SPICE): the year 1 BCE is represented as 0, 2 BCE as -1, etc. Hence, around the year 0, the numbering is …, -2 (3 BCE), -1 (2 BCE), 0 (1 BCE), 1 (1 CE), 2 (2 CE), et cetera. In this manner, the year numbering proceeds smoothly through 0.

Source

pub const fn month(&self) -> Month

Returns the month stored inside this proleptic Gregorian date.

Source

pub const fn day(&self) -> u8

Returns the day-of-month stored inside this proleptic Gregorian date.

Source§

impl GregorianDate

Source

pub fn parse_partial( string: &str, ) -> Result<(Self, &str), GregorianDateParsingError>

Parses a GregorianDate based on some string. Accepts only the extended complete calendar date format specified in ISO 8601 (see section 5.2.2.1), though in addition any number of digits is accepted for the years term - to extend applicability of the format to a larger time range.

On success, returns the resulting GregorianDate and any remaining input that was not yet parsed. On failure, returns a reason indicating why.

Trait Implementations§

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 From<Date> for GregorianDate

Source§

fn from(value: Date) -> Self

Converts to this type from the input type.
Source§

impl From<GregorianDate> for Date

Source§

fn from(value: GregorianDate) -> Self

Converts to this type from the input type.
Source§

impl FromStr for GregorianDate

Source§

fn from_str(string: &str) -> Result<Self, Self::Err>

Parses a GregorianDate based on some string. Accepts only the extended complete calendar date format specified in ISO 8601 (see section 5.2.2.1), though in addition any number of digits is accepted for each term.

Source§

type Err = GregorianDateParsingError

The associated error which can be returned from parsing.
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> 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.