pub struct Date {
pub year: i32,
pub month: u32,
pub day: u32,
}Expand description
A simple calendar date (year, month, day) in the Gregorian calendar.
Fields§
§year: i32§month: u32§day: u32Implementations§
Source§impl Date
impl Date
Sourcepub fn new(year: i32, month: u32, day: u32) -> Option<Self>
pub fn new(year: i32, month: u32, day: u32) -> Option<Self>
Creates a new date, validating month (1..=12) and day (1..=days_in_month).
pub fn is_leap_year(year: i32) -> bool
pub fn days_in_month(year: i32, month: u32) -> u32
Sourcepub fn to_day_number(&self) -> i64
pub fn to_day_number(&self) -> i64
Converts the date into an ordinal day count (days since 0001-01-01).
Sourcepub fn days_until(&self, other: &Date) -> i64
pub fn days_until(&self, other: &Date) -> i64
Returns the number of actual elapsed calendar days from self to other (other - self).
Sourcepub fn is_month_end(&self) -> bool
pub fn is_month_end(&self) -> bool
Whether this is the last day of its month.
Sourcepub fn add_months(&self, months: i32) -> Date
pub fn add_months(&self, months: i32) -> Date
Shifts by whole months, clamping the day to the length of the target month: 31 August minus six months is 28 (or 29) February, not an invalid 31 February.
Clamping is not the same as the month-end rule — see CouponSchedule, which applies that
rule on top when the anchor date is itself a month end.
Sourcepub fn to_month_end(&self) -> Date
pub fn to_month_end(&self) -> Date
Moves to the last day of its month.
Trait Implementations§
impl Copy for Date
Source§impl<'de> Deserialize<'de> for Date
impl<'de> Deserialize<'de> for Date
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Date
Source§impl Ord for Date
impl Ord for Date
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Date
impl PartialOrd for Date
impl StructuralPartialEq for Date
Auto Trait Implementations§
impl Freeze for Date
impl RefUnwindSafe for Date
impl Send for Date
impl Sync for Date
impl Unpin for Date
impl UnsafeUnpin for Date
impl UnwindSafe for Date
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more