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
impl GregorianDate
Sourcepub const fn new(
year: i32,
month: Month,
day: u8,
) -> Result<Self, InvalidGregorianDate>
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.
Sourcepub const fn from_date(date: Date) -> Self
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.
Sourcepub const fn into_date(&self) -> Date
pub const fn into_date(&self) -> Date
Constructs a Date from a given Gregorian date. Uses Howard Hinnant’s days_from_civil
algorithm.
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.
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.
Source§impl GregorianDate
impl GregorianDate
Sourcepub fn parse_partial(
string: &str,
) -> Result<(Self, &str), GregorianDateParsingError>
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
impl Clone for GregorianDate
Source§fn clone(&self) -> GregorianDate
fn clone(&self) -> GregorianDate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GregorianDate
impl Debug for GregorianDate
Source§impl From<Date> for GregorianDate
impl From<Date> for GregorianDate
Source§impl From<GregorianDate> for Date
impl From<GregorianDate> for Date
Source§fn from(value: GregorianDate) -> Self
fn from(value: GregorianDate) -> Self
Source§impl FromStr for GregorianDate
impl FromStr for GregorianDate
Source§fn from_str(string: &str) -> Result<Self, Self::Err>
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.