Date

Struct Date 

Source
pub struct Date {
    pub year: i32,
    pub month: u8,
    pub day: u8,
}
Expand description

Gregorian calendar date (proleptic).

This is independent of any time zone; think “calendar day in UTC”.

Fields§

§year: i32§month: u8§day: u8

Implementations§

Source§

impl Date

Source

pub fn from_ymd(year: i32, month: u8, day: u8) -> Result<Self, DateError>

Construct a date, validating year/month/day.

Source

pub const fn from_ymd_unchecked(year: i32, month: u8, day: u8) -> Self

Construct a date with minimal checking; debug-only asserts.

Panics in debug builds if the date is invalid.

Source

pub fn from_days_since_unix_epoch(days: i64) -> Result<Self, DateError>

Ben Joffe’s fast 64-bit days→date algorithm, adapted to Rust.

days is days since Unix epoch:

  • 1970-01-01 => 0
  • 1969-12-31 => -1
Source

pub fn days_since_unix_epoch(self) -> i64

Convert to days since Unix epoch (1970-01-01 = 0).

This uses Howard Hinnant’s well-known constant-time civil→days algorithm, which is exact for the proleptic Gregorian calendar.

Source

pub fn weekday(self) -> Weekday

Day of week (Monday = 1).

Unix epoch 1970-01-01 was a Thursday, so we just offset.

Source

pub fn ordinal(self) -> u16

Day of year, 1..=365 (or 366 for leap years).

Source

pub fn add_days(self, days: i64) -> Result<Date, DateError>

Add a number of days, returning a new Date or OutOfRange.

Trait Implementations§

Source§

impl Clone for Date

Source§

fn clone(&self) -> Date

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 Date

Source§

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

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

impl Display for Date

Source§

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

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

impl FromStr for Date

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse “YYYY-MM-DD” (no timezone).

Source§

type Err = DateError

The associated error which can be returned from parsing.
Source§

impl Hash for Date

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 PartialEq for Date

Source§

fn eq(&self, other: &Date) -> 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 Copy for Date

Source§

impl Eq for Date

Source§

impl StructuralPartialEq for Date

Auto Trait Implementations§

§

impl Freeze for Date

§

impl RefUnwindSafe for Date

§

impl Send for Date

§

impl Sync for Date

§

impl Unpin for Date

§

impl UnwindSafe for Date

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.