pub struct Date(/* private fields */);Expand description
A calendar date, stored as days since Unix epoch (1970-01-01).
Range: roughly year -5,879,610 to +5,879,610.
§Examples
use grafeo_common::types::Date;
let d = Date::from_ymd(2024, 3, 15).unwrap();
assert_eq!(d.year(), 2024);
assert_eq!(d.month(), 3);
assert_eq!(d.day(), 15);
assert_eq!(d.to_string(), "2024-03-15");Implementations§
Source§impl Date
impl Date
Sourcepub fn from_ymd(year: i32, month: u32, day: u32) -> Option<Self>
pub fn from_ymd(year: i32, month: u32, day: u32) -> Option<Self>
Creates a date from year, month (1-12), and day (1-31).
Returns None if the components are out of range.
Sourcepub fn to_timestamp(self) -> Timestamp
pub fn to_timestamp(self) -> Timestamp
Converts this date to a timestamp at midnight UTC.
Sourcepub fn add_duration(self, dur: &Duration) -> Self
pub fn add_duration(self, dur: &Duration) -> Self
Adds a duration to this date.
Month components are added first (clamping day to month’s max), then day components.
Sourcepub fn sub_duration(self, dur: &Duration) -> Self
pub fn sub_duration(self, dur: &Duration) -> Self
Subtracts a duration from this date.
Trait Implementations§
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
Source§impl Ord for Date
impl Ord for Date
Source§impl PartialOrd for Date
impl PartialOrd for Date
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 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
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.