datetime

Struct LocalDate

Source
pub struct LocalDate { /* private fields */ }
Expand description

A local date is a day-long span on the timeline, without a time zone.

Implementations§

Source§

impl LocalDate

Source

pub fn ymd(year: i64, month: Month, day: i8) -> Result<Self, Error>

Creates a new local date instance from the given year, month, and day fields.

The values are checked for validity before instantiation, and passing in values out of range will return an error.

§Examples

Instantiate the 20th of July 1969 based on its year, week-of-year, and weekday.

use datetime::{LocalDate, Month, DatePiece};

let date = LocalDate::ymd(1969, Month::July, 20).unwrap();
assert_eq!(date.year(), 1969);
assert_eq!(date.month(), Month::July);
assert_eq!(date.day(), 20);

assert!(LocalDate::ymd(2100, Month::February, 29).is_err());
Source

pub fn yd(year: i64, yearday: i64) -> Result<Self, Error>

Creates a new local date instance from the given year and day-of-year values.

The values are checked for validity before instantiation, and passing in values out of range will return an error.

§Examples

Instantiate the 13th of September 2015 based on its year and day-of-year.

use datetime::{LocalDate, Weekday, Month, DatePiece};

let date = LocalDate::yd(2015, 0x100).unwrap();
assert_eq!(date.year(), 2015);
assert_eq!(date.month(), Month::September);
assert_eq!(date.day(), 13);
Source

pub fn ywd(year: i64, week: i64, weekday: Weekday) -> Result<Self, Error>

Creates a new local date instance from the given year, week-of-year, and weekday values.

The values are checked for validity before instantiation, and passing in values out of range will return an error.

§Examples

Instantiate the 11th of September 2015 based on its year, week-of-year, and weekday.

use datetime::{LocalDate, Weekday, Month, DatePiece};

let date = LocalDate::ywd(2015, 37, Weekday::Friday).unwrap();
assert_eq!(date.year(), 2015);
assert_eq!(date.month(), Month::September);
assert_eq!(date.day(), 11);
assert_eq!(date.weekday(), Weekday::Friday);

Note that according to the ISO-8601 standard, the year will change when working with dates early in week 1, or late in week 53:

use datetime::{LocalDate, Weekday, Month, DatePiece};

let date = LocalDate::ywd(2009, 1, Weekday::Monday).unwrap();
assert_eq!(date.year(), 2008);
assert_eq!(date.month(), Month::December);
assert_eq!(date.day(), 29);
assert_eq!(date.weekday(), Weekday::Monday);

let date = LocalDate::ywd(2009, 53, Weekday::Sunday).unwrap();
assert_eq!(date.year(), 2010);
assert_eq!(date.month(), Month::January);
assert_eq!(date.day(), 3);
assert_eq!(date.weekday(), Weekday::Sunday);
Source

pub unsafe fn _new_with_prefilled_values( year: i64, month: Month, day: i8, weekday: Weekday, yearday: i16, ) -> Self

Creates a new datestamp instance with the given year, month, day, weekday, and yearday fields.

This function is unsafe because the values are not checked for validity! It’s possible to pass the wrong values in, such as having a wrong day value for a month, or having the yearday value out of step. Before using it, check that the values are all correct - or just use the date!() macro, which does this for you at compile-time.

For this reason, the function is marked as unsafe, even though it (technically) uses unsafe components.

Trait Implementations§

Source§

impl Clone for LocalDate

Source§

fn clone(&self) -> LocalDate

Returns a copy 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 DatePiece for LocalDate

Source§

fn year(&self) -> i64

The year, in absolute terms. This is in human-readable format, so the year 2014 actually has a year value of 2014, rather than 14 or 114 or anything like that.
Source§

fn month(&self) -> Month

The month of the year.
Source§

fn day(&self) -> i8

The day of the month, from 1 to 31.
Source§

fn yearday(&self) -> i16

The day of the year, from 1 to 366.
Source§

fn weekday(&self) -> Weekday

The day of the week.
Source§

fn year_of_century(&self) -> i64

The number of years into the century. This is the same as the last two digits of the year.
Source§

fn years_from_2000(&self) -> i64

The year number, relative to the year 2000. Internally, many routines use years relative the year 2000, rather than the year 0 (well, 1 BCE).
Source§

impl Debug for LocalDate

Source§

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

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

impl FromStr for LocalDate

Source§

type Err = Error<Error>

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

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

Parses a string s to return a value of this type. Read more
Source§

impl ISO for LocalDate

Source§

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

Source§

fn iso(&self) -> ISOString<'_, Self>

Source§

impl Ord for LocalDate

Source§

fn cmp(&self, other: &Self) -> 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 LocalDate

Source§

fn eq(&self, other: &Self) -> 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 LocalDate

Source§

fn partial_cmp(&self, other: &Self) -> 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 Today for LocalDate

Source§

impl Copy for LocalDate

Source§

impl Eq for LocalDate

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.