pub struct Date(pub NaiveDate);Expand description
A calendar date without a time zone, as HEY writes starts_on and ends_on.
Two dates compare and sort chronologically, so use <, > and == rather than
looking for before and after.
Tuple Fields§
§0: NaiveDateImplementations§
Source§impl Date
impl Date
Sourcepub fn new(year: i32, month: u32, day: u32) -> Option<Date>
pub fn new(year: i32, month: u32, day: u32) -> Option<Date>
The date at year, month and day, or None when the calendar has no such day.
Sourcepub fn parse(source: &str) -> Result<Date, Error>
pub fn parse(source: &str) -> Result<Date, Error>
Reads YYYY-MM-DD. An empty string is not a date and is rejected as one.
Sourcepub fn from_datetime(moment: &DateTime) -> Date
pub fn from_datetime(moment: &DateTime) -> Date
The date an instant falls on in UTC.
Sourcepub fn from_datetime_in<Tz: TimeZone>(moment: &DateTime, zone: &Tz) -> Date
pub fn from_datetime_in<Tz: TimeZone>(moment: &DateTime, zone: &Tz) -> Date
The date an instant falls on in the given time zone, which is a different day from
Date::from_datetime either side of midnight.
Sourcepub fn at_midnight_utc(&self) -> DateTime
pub fn at_midnight_utc(&self) -> DateTime
Midnight UTC on this date.
UTC is the only zone this crate turns a date into an instant in: naming another
would mean a time zone database, and the crate carries none. To land on midnight
somewhere else, build the instant with a chrono::TimeZone of your own —
zone.from_local_datetime(&date.0.and_time(NaiveTime::MIN)).
Sourcepub fn add_days(&self, days: i64) -> Option<Date>
pub fn add_days(&self, days: i64) -> Option<Date>
The date days later, or earlier for a negative count; None past the calendar’s
range.
Sourcepub fn add_months(&self, months: i32) -> Option<Date>
pub fn add_months(&self, months: i32) -> Option<Date>
Adds months the way Go’s time.AddDate does: the day of the month is kept and a
month too short to hold it rolls over into the next one, so 31 January plus one
month is 3 March in a common year rather than 28 February.
Sourcepub fn add_years(&self, years: i32) -> Option<Date>
pub fn add_years(&self, years: i32) -> Option<Date>
Adds years with the same rollover as Date::add_months: 29 February plus one
year is 1 March.
Sourcepub fn days_since(&self, earlier: Date) -> i64
pub fn days_since(&self, earlier: Date) -> i64
The whole days from earlier to this date, negative when this date came first.
Trait Implementations§
impl Copy for Date
Source§impl<'de> Deserialize<'de> for Date
impl<'de> Deserialize<'de> for Date
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Date, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Date, D::Error>
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
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
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.