pub struct Date { /* private fields */ }
Expand description
A calendar date consting of a year, month and day.
All dates in the library use the proleptic Gregorian calendar with a year 0.
Implementations
sourceimpl Date
impl Date
sourcepub fn new<Y, M>(year: Y, month: M, day: u8) -> Result<Self, InvalidDate>where
Y: Into<Year>,
M: TryInto<Month>,
InvalidDate: From<M::Error>,
pub fn new<Y, M>(year: Y, month: M, day: u8) -> Result<Self, InvalidDate>where
Y: Into<Year>,
M: TryInto<Month>,
InvalidDate: From<M::Error>,
Create a new date from a year, month and day.
Month and day numbers start at 1.
sourcepub const fn new_const(
year: Year,
month: Month,
day: u8
) -> Result<Self, InvalidDayOfMonth>
pub const fn new_const(
year: Year,
month: Month,
day: u8
) -> Result<Self, InvalidDayOfMonth>
Create a new date from a year, month and day.
Day numbers start at 1.
sourcepub const unsafe fn new_unchecked(year: Year, month: Month, day: u8) -> Self
pub const unsafe fn new_unchecked(year: Year, month: Month, day: u8) -> Self
Create a new date without checking the validity.
Month and day numbers start at 1.
Safety
Although this is currently not the case, future implementations may rely on date validity for memory safety
sourcepub const fn from_unix_timestamp(seconds: i64) -> Self
pub const fn from_unix_timestamp(seconds: i64) -> Self
Get the date for a unix timestamp.
The timestamp is interpreted as number of seconds since 1 January 1970 00:00, not including any leap seconds.
sourcepub const fn to_unix_timestamp(self) -> i64
pub const fn to_unix_timestamp(self) -> i64
Get the unix timestamp for a date.
The timestamp is the number of seconds since 1 January 1970 00:00.
The returned timestamp is valid for time 00:00 of the date.
sourcepub const fn year_month(self) -> YearMonth
pub const fn year_month(self) -> YearMonth
Get the year and month as YearMonth
.
sourcepub const fn day_of_year(self) -> u16
pub const fn day_of_year(self) -> u16
Get the day of the year.
The returned number is 1-based. For January 1, this function will return 1.
sourcepub const fn days_remaining_in_year(self) -> u16
pub const fn days_remaining_in_year(self) -> u16
The number of days remaining in the year, including the current date.
For Janury 1 this will return 365 in a non-leap year or 366 in a leap year. For December 31, this will return 1.
sourcepub const fn days_since_year_zero(self) -> i32
pub const fn days_since_year_zero(self) -> i32
Get the total number of days since 1 January 0000.
The returned value is zero-based. For 1 January 0000, this function returns 0.
sourcepub const fn from_days_since_year_zero(days: i32) -> Self
pub const fn from_days_since_year_zero(days: i32) -> Self
Get the date corresponding to a number of days since the year zero.
For this function, day 0 is 1 January of year 0.
sourcepub const fn add_months(self, months: i32) -> Result<Self, InvalidDayOfMonth>
pub const fn add_months(self, months: i32) -> Result<Self, InvalidDayOfMonth>
Compute a date by adding a number of months.
The resulting date may not be valid.
You can call InvalidDayOfMonth::next_valid()
or InvalidDayOfMonth::prev_valid()
to get the first day of the next month or the last day of resulting month.
sourcepub const fn sub_months(self, months: i32) -> Result<Self, InvalidDayOfMonth>
pub const fn sub_months(self, months: i32) -> Result<Self, InvalidDayOfMonth>
Compute a date by subtracting a number of months.
The resulting date may not be valid.
You can call InvalidDayOfMonth::next_valid()
or InvalidDayOfMonth::prev_valid()
to get the first day of the next month or the last day of resulting month.
sourcepub const fn add_years(self, years: i16) -> Result<Self, InvalidDayOfMonth>
pub const fn add_years(self, years: i16) -> Result<Self, InvalidDayOfMonth>
Compute a date by adding a number of years.
The resulting date may not be valid.
You can call InvalidDayOfMonth::next_valid()
or InvalidDayOfMonth::prev_valid()
to get the first day of the next month or the last day of resulting month.
sourcepub const fn sub_years(self, years: i16) -> Result<Self, InvalidDayOfMonth>
pub const fn sub_years(self, years: i16) -> Result<Self, InvalidDayOfMonth>
Compute a date by subtracting a number of years.
The resulting date may not be valid.
You can call InvalidDayOfMonth::next_valid()
or InvalidDayOfMonth::prev_valid()
to get the first day of the next month or the last day of resulting month.
sourcepub const fn days_since(self, other: Date) -> i32
pub const fn days_since(self, other: Date) -> i32
Compute the difference in days between two dates.
This does not include the end date. For example, difference between the same date will be 0.
Trait Implementations
sourceimpl Ord for Date
impl Ord for Date
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialOrd<Date> for Date
impl PartialOrd<Date> for Date
sourcefn partial_cmp(&self, other: &Date) -> Option<Ordering>
fn partial_cmp(&self, other: &Date) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more