pub struct Date {
pub year: i32,
pub month: u32,
pub day: u32,
}Expand description
A proleptic-Gregorian calendar date (YYYY-MM-DD).
Ordering is chronological: the derived field order (year, month, day) is exactly calendar order.
Fields§
§year: i32Calendar year.
month: u32Month, 1 to 12.
day: u32Day of month, 1 to 31 (validated against the month and leap year).
Implementations§
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>
Builds a date, returning None for a day that does not exist in that
month (2026-02-30, 2026-13-01, …).
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parses a strict YYYY-MM-DD date. Returns None for any other shape,
including datetimes; use DateTime::parse for those.
Sourcepub fn today_utc() -> Option<Self>
pub fn today_utc() -> Option<Self>
Today’s date in UTC, from the system clock.
Returns None only if the clock reports a time before the Unix epoch.
Sourcepub fn days_since_epoch(&self) -> i64
pub fn days_since_epoch(&self) -> i64
Days since 1970-01-01 (negative before it).
Sourcepub fn from_days_since_epoch(days: i64) -> Self
pub fn from_days_since_epoch(days: i64) -> Self
The date days after 1970-01-01.
Sourcepub const fn to_utc_datetime(&self) -> DateTime
pub const fn to_utc_datetime(&self) -> DateTime
Returns a UTC datetime at midnight (00:00:00Z) on this date.
Trait Implementations§
impl Copy for Date
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
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