pub struct Date { /* private fields */ }Expand description
A day in the proleptic Gregorian calendar.
Fields are private and Date::new is checked, so nothing downstream —
including the grid below — ever has to ask whether a date is real. Ordering
is chronological, which is what the field order buys.
Implementations§
Source§impl Date
impl Date
Sourcepub fn new(year: i32, month: u8, day: u8) -> Option<Self>
pub fn new(year: i32, month: u8, day: u8) -> Option<Self>
None unless the day exists: month in 1..=12, day within that month’s
own length, in that year — so 29 February answers differently depending
on the year, which is the whole point of asking.
pub fn year(self) -> i32
pub fn month(self) -> u8
pub fn day(self) -> u8
Sourcepub fn to_days(self) -> i64
pub fn to_days(self) -> i64
Days since 1970-01-01, negative before it.
Howard Hinnant’s days_from_civil, transcribed rather than re-derived
(http://howardhinnant.github.io/date_algorithms.html, public domain).
It is exact across the whole proleptic Gregorian range, and every other
operation here is a round trip through it and its inverse — so there is
one piece of calendar arithmetic in this file, not six.
Sourcepub fn from_days(days: i64) -> Self
pub fn from_days(days: i64) -> Self
The inverse of Date::to_days — Hinnant’s civil_from_days. Total by
construction: every integer is a day.
pub fn add_days(self, days: i64) -> Self
Sourcepub fn add_months(self, months: i32) -> Self
pub fn add_months(self, months: i32) -> Self
Whole months, keeping the day where the target month has one: 31 January plus a month is 28 February, not 3 March. Clamping is what a calendar’s month arrows mean — adding thirty days is a different question.
pub fn weekday(self) -> Weekday
Trait Implementations§
impl Copy for Date
Source§impl Display for Date
ISO 8601, because it is the one written form no locale argues with and it
sorts. An app wanting “17 Aug” formats it from the accessors — that is its
call to make, not a component library’s.
impl Display for Date
ISO 8601, because it is the one written form no locale argues with and it sorts. An app wanting “17 Aug” formats it from the accessors — that is its call to make, not a component library’s.
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,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more