Struct UnixEpochDay
pub struct UnixEpochDay { /* private fields */ }
A civil date represented by a number of days since the Unix epoch (1970-01-01).
The date can be positive (occurs after 1970-01-01) or negative (occurs before 1970-01-01). A zero value corresponds to 1970-01-01.
Unix epoch days can be infallibly converted to and from Date values.
Implementations
impl UnixEpochDay
const MIN: UnixEpochDay = _;The minimum allowed Unix epoch day.
This is guaranteed to be equivalent to
Date::MINwhen converted to a Gregorian date.const MAX: UnixEpochDay = _;The maximum allowed Unix epoch day.
This is guaranteed to be equivalent to
Date::MAXwhen converted to a Gregorian date.const fn new(day: i32) -> Result<UnixEpochDay, RangeError>Creates a new Unix epoch day.
The day given must correspond to a number of days (positive or negative) since the Unix epoch (1970-01-01). A value of
0corresponds to1970-01-01.const fn day(self) -> i32Returns the underlying day value.
This is guaranteed to be in the
UnixEpochDaysrange.const fn weekday(&self) -> WeekdayReturns the day of the week for this epoch day.
const fn nth_weekday(self, nth: i32, weekday: Weekday) -> Result<Date, RangeError>Returns the "nth" weekday from this date, not including itself.
The
nthparameter can be positive or negative. A positive value computes the "nth" weekday starting at the day after this date and going forwards in time. A negative value computes the "nth" weekday starting at the day before this date and going backwards in time.For example, if this date's weekday is a Sunday and the first Sunday is asked for (that is,
date.nth_weekday(1, Weekday::Sunday)), then the result is a week from this date corresponding to the following Sunday.const fn checked_add(self, days: i32) -> Result<UnixEpochDay, RangeError>Add the given number of days to this Unix epoch day.
If this would overflow an
i32or result in an out-of-bounds Unix epoch day, then this returns an error.const fn checked_sub(self, days: i32) -> Result<UnixEpochDay, RangeError>Subtracts the given number of days from this Unix epoch day.
If this would overflow an
i32or result in an out-of-bounds Unix epoch day, then this returns an error.const fn until(self, other: UnixEpochDay) -> i32Returns the number of days from this date until
other.This routine never overflows because of the enforced range on
UnixEpochDayvalues.Example
use jiff_core::civil::date; let date1 = date(2023, 7, 1).to_unix_epoch_day(); let date2 = date(2024, 7, 1).to_unix_epoch_day(); assert_eq!(366, date1.until(date2)); // The value will be negative when the dates are flipped: assert_eq!(-366, date2.until(date1));Example: overflow isn't possible
Even when using the minimum or maximum values:
use jiff_core::civil::UnixEpochDay; assert_eq!(7_304_483, UnixEpochDay::MIN.until(UnixEpochDay::MAX)); assert_eq!(-7_304_483, UnixEpochDay::MAX.until(UnixEpochDay::MIN));const fn since(self, other: UnixEpochDay) -> i32Returns the number of days from this date since
other.This routine never overflows because of the enforced range on
UnixEpochDayvalues.Example
use jiff_core::civil::date; let date1 = date(2023, 7, 1).to_unix_epoch_day(); let date2 = date(2024, 7, 1).to_unix_epoch_day(); assert_eq!(366, date2.since(date1)); // The value will be negative when the dates are flipped: assert_eq!(-366, date1.since(date2));Example: overflow isn't possible
Even when using the minimum or maximum values:
use jiff_core::civil::UnixEpochDay; assert_eq!(7_304_483, UnixEpochDay::MAX.since(UnixEpochDay::MIN));const fn to_date(self) -> DateConverts this Unix epoch day to a Gregorian date.
Trait Implementations
impl Clone for UnixEpochDay
fn clone(&self) -> Self
impl Copy for UnixEpochDay
impl Debug for UnixEpochDay
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for UnixEpochDay
impl Hash for UnixEpochDay
fn hash<__H: Hasher>(&self, state: &mut __H)
impl Ord for UnixEpochDay
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for UnixEpochDay
fn eq(&self, other: &Self) -> bool
impl PartialOrd for UnixEpochDay
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl StructuralPartialEq for UnixEpochDay
impl Sub for UnixEpochDay
type Output = i32;fn sub(self, rhs: UnixEpochDay) -> i32