pub struct UnixEpochDay { /* private fields */ }Expand description
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§
Source§impl UnixEpochDay
impl UnixEpochDay
Sourcepub const MIN: UnixEpochDay
pub const MIN: UnixEpochDay
The minimum allowed Unix epoch day.
This is guaranteed to be equivalent to Date::MIN when
converted to a Gregorian date.
Sourcepub const MAX: UnixEpochDay
pub const MAX: UnixEpochDay
The maximum allowed Unix epoch day.
This is guaranteed to be equivalent to Date::MAX when
converted to a Gregorian date.
Sourcepub const fn new(day: i32) -> Result<UnixEpochDay, RangeError>
pub 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 0 corresponds
to 1970-01-01.
Sourcepub const fn day(self) -> i32
pub const fn day(self) -> i32
Returns the underlying day value.
This is guaranteed to be in the UnixEpochDays
range.
Sourcepub const fn nth_weekday(
self,
nth: i32,
weekday: Weekday,
) -> Result<Date, RangeError>
pub const fn nth_weekday( self, nth: i32, weekday: Weekday, ) -> Result<Date, RangeError>
Returns the “nth” weekday from this date, not including itself.
The nth parameter 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.
Sourcepub const fn checked_add(self, days: i32) -> Result<UnixEpochDay, RangeError>
pub 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 i32 or result in an out-of-bounds Unix
epoch day, then this returns an error.
Sourcepub const fn checked_sub(self, days: i32) -> Result<UnixEpochDay, RangeError>
pub 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 i32 or result in an out-of-bounds Unix
epoch day, then this returns an error.
Sourcepub const fn until(self, other: UnixEpochDay) -> i32
pub const fn until(self, other: UnixEpochDay) -> i32
Returns the number of days from this date until other.
This routine never overflows because of the enforced range on
UnixEpochDay values.
§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));Sourcepub const fn since(self, other: UnixEpochDay) -> i32
pub const fn since(self, other: UnixEpochDay) -> i32
Returns the number of days from this date since other.
This routine never overflows because of the enforced range on
UnixEpochDay values.
§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));Trait Implementations§
Source§impl Clone for UnixEpochDay
impl Clone for UnixEpochDay
Source§fn clone(&self) -> UnixEpochDay
fn clone(&self) -> UnixEpochDay
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for UnixEpochDay
Source§impl Debug for UnixEpochDay
impl Debug for UnixEpochDay
impl Eq for UnixEpochDay
Source§impl Format for UnixEpochDay
impl Format for UnixEpochDay
Source§impl Hash for UnixEpochDay
impl Hash for UnixEpochDay
Source§impl Ord for UnixEpochDay
impl Ord for UnixEpochDay
Source§fn cmp(&self, other: &UnixEpochDay) -> Ordering
fn cmp(&self, other: &UnixEpochDay) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for UnixEpochDay
impl PartialEq for UnixEpochDay
Source§impl PartialOrd for UnixEpochDay
impl PartialOrd for UnixEpochDay
impl StructuralPartialEq for UnixEpochDay
Source§impl Sub for UnixEpochDay
Returns the number of days between two UnixEpochDay values.
impl Sub for UnixEpochDay
Returns the number of days between two UnixEpochDay values.
This routine never overflows because of the enforced range on
UnixEpochDay values.
§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 - date1);
// The value will be negative when the dates are flipped:
assert_eq!(-366, date1 - 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 - UnixEpochDay::MIN);