Struct Date

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

Implementation of a date in the historic calendar. After 15 October 1582, this coincides with the Gregorian calendar; until 4 October 1582, this is the Julian calendar. The days inbetween do not exist.

This is the calendar that is also used by IAU SOFA and NAIF SPICE, as well as Meeus in his Astronomical Algorithms book. Hence, most users probably expect it to be the calendar of choice.

Implementations§

Source§

impl Date

Source

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

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

This function will never panic.

Source

pub const fn from_year_day( 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 to_local_days(self) -> LocalDays<i64>

Constructs a MJD from a given historic calendar date. Applies a slight variation on the approach described by Meeus in Astronomical Algorithms (Chapter 7, Julian Day). This variation adapts the algorithm to the Unix epoch and removes the dependency on floating point arithmetic.

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

pub const fn day_of_year(&self) -> u16

Returns the day-of-year of this specific date, within its calendar year. The day-of-year is an integer value ranging from 1 on January 1 to 365 (or 365, in leap years) on December 31. Uses the algorithm given by Meeus in Astronomical Algorithms.

Source

pub const fn is_gregorian(&self) -> bool

Returns whether the current date falls within the Gregorian (true) or Julian (false) part of the historic calendar.

Source

pub const fn days_in_month(year: i32, month: Month) -> u8

Returns the number of days in a given month of a year. Also considers whether the given year-month combination would fall in the Gregorian or Julian calendar.

Trait Implementations§

Source§

impl Clone for Date

Source§

fn clone(&self) -> Date

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 Date

Source§

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

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

impl From<Date> for LocalDays<i64>

Source§

fn from(value: Date) -> Self

Converts to this type from the input type.
Source§

impl Ord for Date

Source§

fn cmp(&self, other: &Date) -> 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 Date

Source§

fn eq(&self, other: &Date) -> 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 Date

Source§

fn partial_cmp(&self, other: &Date) -> 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 Sub for Date

Source§

fn sub(self, rhs: Self) -> Self::Output

The difference between two Gregorian dates can be computed exactly as a number of days, accounting for the variable number of days per leap year. Note that this is only possible up to an accuracy of days because leap seconds depend on the time scale.

Source§

type Output = Duration<i64, LiteralRatio<86400>>

The resulting type after applying the - operator.
Source§

impl Copy for Date

Source§

impl Eq for Date

Source§

impl StructuralPartialEq for Date

Auto Trait Implementations§

§

impl Freeze for Date

§

impl RefUnwindSafe for Date

§

impl Send for Date

§

impl Sync for Date

§

impl Unpin for Date

§

impl UnwindSafe for Date

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.
Source§

impl<To, From> TryIntoExact<To> for From
where To: TryFromExact<From>,

Source§

type Error = <To as TryFromExact<From>>::Error

Source§

fn try_into_exact(self) -> Result<To, <From as TryIntoExact<To>>::Error>