Date

Struct Date 

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

Represents a date.

Implementations§

Source§

impl Date

Source

pub const UNIX_EPOCH: Self

Source

pub const fn year(self) -> u32

The year for this date.

Source

pub const fn month_int(self) -> u8

The month for this date as an int, between 1 and 12.

Source

pub fn month(self) -> Month

The month for this date.

Source

pub const fn day(self) -> u8

The day of the month for this date, as an int between 1 and 31.

Source

pub const fn create(year: u32, month: Month, day: u8) -> Result<Self, DateError>

Create a date based on a year, a month, and a day.

Source

pub fn to_string_iso8601_extended(self) -> String

String representation for the current date, e.g. “2021-01-16”.

Source

pub fn to_string_iso8601_basic(self) -> String

String representation for the current date, e.g. “20210116”.

Source

pub fn to_string_american(self) -> String

String representation for the current date, e.g. “01/16/2021”.

Source

pub fn add_days(self, n: i32) -> Self

Add a number of days to this date.

Source

pub fn add_months(self, m: i32) -> Self

Add some number of months to a date. This returns the date with the last day of the month in the case where the actual date would be invalid, e.g. adding a month to Jan 31 results in Feb 28 or Feb 29 depending on whether it’s a leap year or not.

Source

pub fn add_years(self, y: i32) -> Self

Add some number of years to a date. If the returned day would not exist (e.g. Feb 28), the last day of the target month is returned.

Source

pub fn day_of_week(self) -> DayOfWeek

The day of the week for this date.

Source

pub fn of_days_since_epoch(d: i32) -> Self

The number of days since epoch (1970-01-01).

Source

pub fn today(tz: Tz) -> Self

The current date in the given timezone, this calls Time::now.

Source

pub fn is_weekday(self) -> bool

Source

pub fn is_weekend(self) -> bool

Source

pub fn round_forward_to_business_day<F>(self, is_business_day: F) -> Self
where F: Fn(Self) -> bool,

Rounds the date to the next value that satisfies is_business_day if it is not already a business day.

Source

pub fn round_backward_to_business_day<F>(self, is_business_day: F) -> Self
where F: Fn(Self) -> bool,

Rounds the date to the previous value that satisfies is_business_day if it is not already a business day.

Source

pub fn add_business_days_rounding_backward<F>( self, days: i64, is_business_day: F, ) -> Self
where F: Fn(Self) -> bool,

First rounds the given date backward to the previous business day as defined by F if it does not already satisfy it. Then advances by the given number of business days which may be negative.

Source

pub fn add_business_days_rounding_forward<F>( self, days: i64, is_business_day: F, ) -> Self
where F: Fn(Self) -> bool,

First rounds the given date forward to the next business day as defined by F if it does not already satisfy it. Then advances by the given number of business days which may be negative.

Source§

impl Date

Source

pub fn dates_between(lo: Self, up: Self) -> DatesBetween

Lists all the dates between two dates (inclusive).

Source

pub fn dates_until(self, up: Self) -> DatesBetween

Lists all the dates from the self date until up (inclusive).

Source§

impl Date

Source

pub fn weekdays_between(lo: Self, up: Self) -> WeekdaysBetween

Lists all the weekdays between two dates (inclusive).

Source

pub fn weekdays_until(self, up: Self) -> WeekdaysBetween

Lists all the weekdays from the self date until up (inclusive).

Source§

impl Date

Source

pub fn business_days_between<F>( lo: Self, up: Self, is_business_day: F, ) -> BusinessDaysBetween<F>
where F: Fn(Self) -> bool,

Lists all the business days between two dates (inclusive).

Source

pub fn business_days_until<F>( self, up: Self, is_business_day: F, ) -> BusinessDaysBetween<F>
where F: Fn(Self) -> bool,

Lists all the business days from the self date until up (inclusive).

Trait Implementations§

Source§

impl Add<i32> for Date

Source§

type Output = Date

The resulting type after applying the + operator.
Source§

fn add(self, other: i32) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<i32> for Date

Source§

fn add_assign(&mut self, other: i32)

Performs the += operation. Read more
Source§

impl BinProtRead for Date

Source§

fn binprot_read<R>(r: &mut R) -> Result<Self, Error>
where R: Read + ?Sized,

Source§

impl BinProtWrite for Date

Source§

fn binprot_write<W>(&self, w: &mut W) -> Result<(), Error>
where W: Write,

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<'de> Deserialize<'de> for Date

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. 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 From<Date> for u32

Source§

fn from(value: Date) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Date

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Date

Source§

type Err = DateError

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

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

Parses a string s to return a value of this type. Read more
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 Ord for Date

Source§

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

Source§

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

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<i32> for Date

Source§

type Output = Date

The resulting type after applying the - operator.
Source§

fn sub(self, other: i32) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Date

Source§

type Output = i32

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<i32> for Date

Source§

fn sub_assign(&mut self, other: i32)

Performs the -= operation. Read more
Source§

impl Copy for Date

Source§

impl Eq for Date

Source§

impl StructuralPartialEq for Date

Source§

impl UseToString for Date

Available on crate feature sexp only.

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> BinProtSize for T
where T: BinProtWrite,

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> OfSexp for T
where T: UseToString + FromStr, <T as FromStr>::Err: Display,

Source§

impl<T> SexpOf for T
where T: ToString + UseToString,

Source§

fn sexp_of(&self) -> Sexp

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,