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::MIN when converted to a Gregorian date.

const MAX: UnixEpochDay = _;

The maximum allowed Unix epoch day.

This is guaranteed to be equivalent to Date::MAX when 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 0 corresponds to 1970-01-01.

const fn day(self) -> i32

Returns the underlying day value.

This is guaranteed to be in the UnixEpochDays range.

const fn weekday(&self) -> Weekday

Returns 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 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.

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.

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.

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));
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));
const fn to_date(self) -> Date

Converts this Unix epoch day to a Gregorian date.

Trait Implementations

impl Clone for UnixEpochDay

fn clone(&self) -> UnixEpochDay

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: &UnixEpochDay) -> Ordering

impl PartialEq for UnixEpochDay

fn eq(&self, other: &UnixEpochDay) -> bool

impl PartialOrd for UnixEpochDay

fn partial_cmp(&self, other: &UnixEpochDay) -> Option<Ordering>

impl StructuralPartialEq for UnixEpochDay

impl Sub for UnixEpochDay

type Output = i32;
fn sub(self, rhs: UnixEpochDay) -> i32

Auto Trait Implementations

impl Freeze for UnixEpochDay

impl RefUnwindSafe for UnixEpochDay

impl Send for UnixEpochDay

impl Sync for UnixEpochDay

impl Unpin for UnixEpochDay

impl UnsafeUnpin for UnixEpochDay

impl UnwindSafe for UnixEpochDay

Blanket Implementations

impl<T> Any for UnixEpochDay where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for UnixEpochDay where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for UnixEpochDay where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for UnixEpochDay where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for UnixEpochDay

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for UnixEpochDay where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for UnixEpochDay where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for UnixEpochDay where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for UnixEpochDay where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>