pub struct Date {
pub year: i32,
pub month: u8,
pub day: u8,
}Expand description
Gregorian calendar date (proleptic).
This is independent of any time zone; think “calendar day in UTC”.
Fields§
§year: i32§month: u8§day: u8Implementations§
Source§impl Date
impl Date
Sourcepub fn from_ymd(year: i32, month: u8, day: u8) -> Result<Self, DateError>
pub fn from_ymd(year: i32, month: u8, day: u8) -> Result<Self, DateError>
Construct a date, validating year/month/day.
Sourcepub const fn from_ymd_unchecked(year: i32, month: u8, day: u8) -> Self
pub const fn from_ymd_unchecked(year: i32, month: u8, day: u8) -> Self
Construct a date with minimal checking; debug-only asserts.
Panics in debug builds if the date is invalid.
Sourcepub fn from_days_since_unix_epoch(days: i64) -> Result<Self, DateError>
pub fn from_days_since_unix_epoch(days: i64) -> Result<Self, DateError>
Ben Joffe’s fast 64-bit days→date algorithm, adapted to Rust.
days is days since Unix epoch:
- 1970-01-01 => 0
- 1969-12-31 => -1
Sourcepub fn days_since_unix_epoch(self) -> i64
pub fn days_since_unix_epoch(self) -> i64
Convert to days since Unix epoch (1970-01-01 = 0).
This uses Howard Hinnant’s well-known constant-time civil→days algorithm, which is exact for the proleptic Gregorian calendar.
Trait Implementations§
impl Copy for Date
impl Eq 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 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