pub struct Date {
pub year: u16,
pub month: u8,
pub day: u8,
}
Expand description
Indicates the date.
Used for the nightly versions of rust.
The timezone is not explicitly specified here, and matches whatever one the rust team uses for nightly releases.
Fields§
§year: u16
The year
month: u8
The month
day: u8
The day of the month.
Implementations§
Source§impl Date
impl Date
Sourcepub const fn new(year: u16, month: u8, day: u8) -> Self
pub const fn new(year: u16, month: u8, day: u8) -> Self
Create a date, using YYYY-MM-DD format (ISO 8601).
For example, Date::new(2018, 10, 21)
If possible, perform some basic validation.
TODO: Don’t make this a const fn
function,
because doing validation is more important.
Sourcepub const fn is_since(&self, start: Date) -> bool
pub const fn is_since(&self, start: Date) -> bool
Check if this date is equal to or after the specified start.
Equivalent to self >= start
,
but available as a const
function.
§Example
assert!(Date::new(2024, 11, 16).is_since(Date::new(2024, 7, 28)));
Sourcepub const fn is_before(&self, end: Date) -> bool
pub const fn is_before(&self, end: Date) -> bool
Check if this date is before the specified end.
Equivalent to self < end
,
but available as a const
function.
§Example
assert!(Date::new(2018, 12, 14).is_before(Date::new(2022, 8, 16)));
assert!(Date::new(2024, 11, 14).is_before(Date::new(2024, 12, 7)));
assert!(Date::new(2024, 11, 14).is_before(Date::new(2024, 11, 17)));
Trait Implementations§
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 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