HistoricDate

Struct HistoricDate 

Source
pub struct HistoricDate { /* 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 HistoricDate

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_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 from_date(date: Date) -> Self

Source

pub const fn into_date(self) -> Date

Constructs a generic date 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 historic 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 historic date.

Source

pub const fn day(&self) -> u8

Returns the day-of-month stored inside this historic 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.

Source§

impl HistoricDate

Source

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

Parses a HistoricDate 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 HistoricDate and any remaining input that was not yet parsed. On failure, returns a reason indicating why.

Trait Implementations§

Source§

impl Clone for HistoricDate

Source§

fn clone(&self) -> HistoricDate

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 HistoricDate

Source§

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

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

impl Display for HistoricDate

Source§

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

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

impl From<Date> for HistoricDate

Source§

fn from(value: Date) -> Self

Converts to this type from the input type.
Source§

impl From<HistoricDate> for Date

Source§

fn from(value: HistoricDate) -> Self

Converts to this type from the input type.
Source§

impl FromStr for HistoricDate

Source§

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

Parses a HistoricDate 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 = HistoricDateParsingError

The associated error which can be returned from parsing.
Source§

impl Ord for HistoricDate

Source§

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

Source§

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

Source§

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

Source§

impl Eq for HistoricDate

Source§

impl StructuralPartialEq for HistoricDate

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.