Struct Date

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

SAC13 date.

Consists of the three components year, month and day. Check the module root documentation for details about the SAC13 calendar and its dates. You can also check out the documentation for Year and Month.

§Examples

use sac13::prelude::*;

// Hard-coded values can be constructed with a compile-time checked macro.
let date = date!(M024 - 03 - 12);

Implementations§

Source§

impl Date

Source

pub const fn from_ymd(year: Year, month: Month, day: u8) -> Option<Self>

SAC13 date from given year, month, day.

Returns None for invalid dates.

Examples

use sac13::prelude::*;

let y = Year::new(12020).unwrap();
let m = Month::new(5).unwrap();

let date = Date::from_ymd(y,m,16).unwrap();
Source

pub const fn from_ymd_untyped(year: u16, month: u8, day: u8) -> Option<Self>

Like from_ymd() but from integers instead of typed Year and Month.

Returns None for invalid dates.

§Examples
use sac13::{Date,date};

assert_eq!(Date::from_ymd_untyped(12020,02,16), Some(date!(M020 - 02 - 16)));
assert_eq!(Date::from_ymd_untyped(12020,02,29), None); // April 29th does not exist in SAC13
Source

pub const fn year(&self) -> Year

Year component of the date.

Source

pub const fn month(&self) -> Month

Month component of the date.

Source

pub const fn day(&self) -> u8

Day component of the date.

Source

pub const fn weekday_ordinal(&self) -> u8

SAC13 Weekday ordinal.

Returns which day of the week it is. Typically 1-7, 8 on synchronization days. Note that 1-7 are NOT synonymous with Monday - Sunday. SAC13 doesn’t have weekdays in the typical sense.

Source

pub const fn month_len(year: Year, month: Month) -> u8

All months have 28 days, except (Addenduary)Month::Addenduary, and (August)Month::August on leap years, which are 29 days long.

Trait Implementations§

Source§

impl CalendarDate for Date

Source§

const MIN: Self

Earliest representable date.
Source§

const MAX: Self

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

Displays the SAC13 date.

use sac13::date;

let formatted_date = format!("{}", date!(M020 - 05 - 21));
assert_eq!(formatted_date, "M020-05-21");
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 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, 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.