Struct UnixDay

Source
pub struct UnixDay(/* private fields */);
Expand description

Days since the Unix Epoch. 1970-01-01 (Gregorian) is day zero.

Important: “Unix Day” is not a Unix timestamp! Neither in seconds nor milliseconds.

§Example

use sac13::prelude::*;
use sac13::day_counts::UnixDay;

const SECONDS_PER_DAY : i32 = 86400;

// This example completely ignores time zones
// and will give you the UnixDay for the timestamp in UTC;
// which technically isn't a time zone, but I think you get the gist.
let unix_timestamp_seconds = 1355313600;
let unix_day = unix_timestamp_seconds / SECONDS_PER_DAY;

let date : Date = UnixDay::new(unix_day).unwrap().convert();

§About Unix Days

The name is actually made up, but the concept is simple. It’s the number of days since the Unix Epoch, so 1.1.1970 (Gregorian) is day zero. Java calls this EPOCH_DAY but because epoch is a bit too unspecific for my taste I named it UnixDay.

§Why do I have to manually convert timestamps?

It was actually a very deliberate choice to not allow construction with unix timestamps directly because if you have a timestamp, you have to think about time zones, or you will get subtle bugs. To force you to think about the conversion we let you do it manually.

Implementations§

Source§

impl UnixDay

Source

pub const MIN_INT: i32 = -4_371_872i32

Earliest representable date (in its native integer type).

Source

pub const MAX_INT: i32 = 5_124_428i32

Latest representable value (in its native integer type).

Source

pub const MIN: Self

Earliest representable date

Source

pub const MAX: Self

Latest representable value

Source

pub const fn new(value: i32) -> Option<Self>

Creates a new UnixDay.

Returns None for invalid values. Valid values are between (and including) MIN_INT (A000-01-01) and MAX_INT (Z999-13-29).

Source

pub const fn value(&self) -> i32

Returns the underlying integer value.

Source

pub const fn tomorrow(&self) -> Option<Self>

Returns the next day. Returns None if the next day is outside the valid SAC13 range.

Source

pub const fn yesterday(&self) -> Option<Self>

Returns the previous day. Returns None if the previous day is outside the valid SAC13 range.

Trait Implementations§

Source§

impl CalendarDate for UnixDay

Source§

const MIN: Self = Self::MIN

Earliest representable date.
Source§

const MAX: Self = Self::MAX

Latest representable date.
Source§

fn as_julian(&self) -> i32

Convert the date into the corresponding Julian Day Number.
Source§

fn from_julian(value: i32) -> Option<Self>

Get the date from the corresponding Julian
Source§

fn tomorrow(self) -> Option<Self>

Source§

fn yesterday(self) -> Option<Self>

Source§

fn convert<T: CalendarDate>(self) -> T

Converts the calendar date to a different calendar system. Read more
Source§

impl Clone for UnixDay

Source§

fn clone(&self) -> UnixDay

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnixDay

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for UnixDay

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for UnixDay

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for UnixDay

Source§

fn cmp(&self, other: &UnixDay) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for UnixDay

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for UnixDay

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for UnixDay

Source§

impl Eq for UnixDay

Source§

impl StructuralPartialEq for UnixDay

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.