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
impl HistoricDate
Sourcepub const fn new(
year: i32,
month: Month,
day: u8,
) -> Result<Self, InvalidHistoricDate>
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.
Sourcepub const fn from_ordinal_date(
year: i32,
day_of_year: u16,
) -> Result<Self, InvalidDayOfYear>
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.
pub const fn from_date(date: Date) -> Self
Sourcepub const fn into_date(self) -> Date
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.
Sourcepub const fn year(&self) -> i32
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.
Sourcepub const fn day_of_year(&self) -> u16
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.
Sourcepub const fn is_gregorian(&self) -> bool
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.
Sourcepub const fn days_in_month(year: i32, month: Month) -> u8
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
impl HistoricDate
Sourcepub fn parse_partial(
string: &str,
) -> Result<(Self, &str), HistoricDateParsingError>
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
impl Clone for HistoricDate
Source§fn clone(&self) -> HistoricDate
fn clone(&self) -> HistoricDate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HistoricDate
impl Debug for HistoricDate
Source§impl Display for HistoricDate
impl Display for HistoricDate
Source§impl From<Date> for HistoricDate
impl From<Date> for HistoricDate
Source§impl From<HistoricDate> for Date
impl From<HistoricDate> for Date
Source§fn from(value: HistoricDate) -> Self
fn from(value: HistoricDate) -> Self
Source§impl FromStr for HistoricDate
impl FromStr for HistoricDate
Source§fn from_str(string: &str) -> Result<Self, Self::Err>
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.