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
impl Date
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_year_day(
year: i32,
day_of_year: u16,
) -> Result<Self, InvalidDayOfYear>
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.
Sourcepub const fn to_local_days(self) -> LocalDays<i64>
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.
Sourcepub const fn year(&self) -> i32
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.
Sourcepub const fn month(&self) -> Month
pub const fn month(&self) -> Month
Returns the month stored inside this proleptic Gregorian date.
Sourcepub const fn day(&self) -> u8
pub const fn day(&self) -> u8
Returns the day-of-month stored inside this proleptic Gregorian date.
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.