pub struct Date { /* private fields */ }Expand description
A civil date: a year, a month and a day on the proleptic Gregorian calendar, with no time of day and no zone. Dates order chronologically.
use predicator_rs::Date;
let date = Date::new(2026, 8, 6).unwrap();
assert_eq!((date.year(), date.month(), date.day()), (2026, 8, 6));
assert_eq!(date.to_string(), "2026-08-06");
assert!(Date::new(2026, 2, 29).is_none());
assert!(date < Date::new(2026, 8, 7).unwrap());Implementations§
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 with these parts, or None when they name no calendar
date (a month outside 1 to 12, a day past the month’s end).
use predicator_rs::Date;
assert!(Date::new(2024, 2, 29).is_some());
assert!(Date::new(2023, 2, 29).is_none());
assert!(Date::new(2024, 13, 1).is_none());Sourcepub fn year(&self) -> i32
pub fn year(&self) -> i32
The year; negative before year 0 (1 BC).
use predicator_rs::Date;
assert_eq!(Date::new(-5, 1, 1).map(|date| date.year()), Some(-5));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>
Reads YYYY-MM-DD with a four-digit year.
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,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Date
impl PartialOrd for Date
impl StructuralPartialEq for Date
Auto Trait Implementations§
impl Forget for Date
impl Freeze for Date
impl Move 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