Struct chrono::naive::internals::Mdf

source ·
pub(super) struct Mdf(u32);
Expand description

Month, day of month and year flags: (month << 9) | (day << 4) | flags M_MMMD_DDDD_LFFF

The whole bits except for the least 3 bits are referred as Mdl (month, day of month, and leap year flag), which is an index to the MDL_TO_OL lookup table.

The conversion between the packed calendar date (Mdf) and the ordinal date (NaiveDate) is based on the moderately-sized lookup table (~1.5KB) and the packed representation is chosen for efficient lookup.

The methods of Mdf validate their inputs as late as possible. Dates that can’t exist, like February 30, can still be represented. This allows the validation to be combined with the final table lookup, which is good for performance.

Tuple Fields§

§0: u32

Implementations§

source§

impl Mdf

source

pub(super) const fn new( month: u32, day: u32, YearFlags: YearFlags, ) -> Option<Mdf>

Makes a new Mdf value from month, day and YearFlags.

This method doesn’t fully validate the range of the month and day parameters, only as much as what can’t be deferred until later. The year flags are trusted to be correct.

§Errors

Returns None if month > 12 or day > 31.

source

pub(super) const fn from_ol(ol: i32, YearFlags: YearFlags) -> Mdf

Makes a new Mdf value from an i32 with an ordinal and a leap year flag, and year flags.

The ol is trusted to be valid, and the flags are trusted to match it.

source

pub(super) const fn month(&self) -> u32

Returns the month of this Mdf.

source

pub(super) const fn with_month(&self, month: u32) -> Option<Mdf>

Replaces the month of this Mdf, keeping the day and flags.

§Errors

Returns None if month > 12.

source

pub(super) const fn day(&self) -> u32

Returns the day of this Mdf.

source

pub(super) const fn with_day(&self, day: u32) -> Option<Mdf>

Replaces the day of this Mdf, keeping the month and flags.

§Errors

Returns None if day > 31.

source

pub(super) const fn with_flags(&self, YearFlags: YearFlags) -> Mdf

Replaces the flags of this Mdf, keeping the month and day.

source

pub(super) const fn ordinal(&self) -> Option<u32>

Returns the ordinal that corresponds to this Mdf.

This does a table lookup to calculate the corresponding ordinal. It will return an error if the Mdl turns out not to be a valid date.

§Errors

Returns None if month == 0 or day == 0, or if a the given day does not exist in the given month.

source

pub(super) const fn year_flags(&self) -> YearFlags

Returns the year flags of this Mdf.

source

pub(super) const fn ordinal_and_flags(&self) -> Option<i32>

Returns the ordinal that corresponds to this Mdf, encoded as a value including year flags.

This does a table lookup to calculate the corresponding ordinal. It will return an error if the Mdl turns out not to be a valid date.

§Errors

Returns None if month == 0 or day == 0, or if a the given day does not exist in the given month.

Trait Implementations§

source§

impl Clone for Mdf

source§

fn clone(&self) -> Mdf

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 Debug for Mdf

source§

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

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

impl PartialEq for Mdf

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Mdf

source§

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

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

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

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Mdf

source§

impl StructuralPartialEq for Mdf

Auto Trait Implementations§

§

impl Freeze for Mdf

§

impl RefUnwindSafe for Mdf

§

impl Send for Mdf

§

impl Sync for Mdf

§

impl Unpin for Mdf

§

impl UnwindSafe for Mdf

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

§

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

§

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

§

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.