pub struct Date { /* private fields */ }Expand description
A proleptic Gregorian calendar date stored as days since 1970-01-01.
Ordering and equality are by serial number, so they coincide with calendar
order. The type is Copy and cheap to pass by value.
Implementations§
Source§impl Date
impl Date
Sourcepub fn new(year: i32, month: u32, day: u32) -> Result<Self, DateError>
pub fn new(year: i32, month: u32, day: u32) -> Result<Self, DateError>
Constructs a date from a calendar (year, month, day).
month is 1–12, day is 1–days_in_month. Returns
DateError::InvalidDate for any out-of-range or nonexistent date
(e.g. month 13, day 0, or February 30).
§Errors
Returns DateError::InvalidDate if the triple is not a real date.
Sourcepub fn from_serial(serial: i32) -> Self
pub fn from_serial(serial: i32) -> Self
Constructs a date directly from its serial number (days since 1970-01-01). Always valid; provided for round-tripping and arithmetic.
Sourcepub fn serial(self) -> i32
pub fn serial(self) -> i32
The serial number: days since 1970-01-01 (negative before the epoch).
Day-count year fractions for actual/N conventions are
(b.serial() - a.serial()) divided by the convention’s basis.
Sourcepub fn ymd(self) -> (i32, u32, u32)
pub fn ymd(self) -> (i32, u32, u32)
(year, month, day) in one call (one serial conversion instead of three).
Sourcepub fn is_weekend(self) -> bool
pub fn is_weekend(self) -> bool
True if the date falls on a Saturday or Sunday. Holiday calendars (a later phase) extend this with named holidays per market.
Sourcepub fn is_leap_year(self) -> bool
pub fn is_leap_year(self) -> bool
True if the date’s year is a Gregorian leap year.
Sourcepub fn add_days(self, n: i32) -> Self
pub fn add_days(self, n: i32) -> Self
Returns this date advanced by n days (negative moves backward).
Sourcepub fn days_until(self, other: Self) -> i32
pub fn days_until(self, other: Self) -> i32
Signed number of days from self to other (other - self).
Sourcepub fn end_of_month(self) -> Self
pub fn end_of_month(self) -> Self
The last day of this date’s month, preserving year and month.
Sourcepub fn is_end_of_month(self) -> bool
pub fn is_end_of_month(self) -> bool
True if this date is the last day of its month.
Sourcepub fn add_period(self, period: Period) -> Self
pub fn add_period(self, period: Period) -> Self
Returns this date advanced by period (negative periods move backward).
Days/weeks add a fixed day count. Months/years use calendar arithmetic
with end-of-month clamping (see Period).