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
impl Mdf
sourcepub(super) const fn new(
month: u32,
day: u32,
YearFlags: YearFlags,
) -> Option<Mdf>
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
.
sourcepub(super) const fn from_ol(ol: i32, YearFlags: YearFlags) -> Mdf
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.
sourcepub(super) const fn with_month(&self, month: u32) -> Option<Mdf>
pub(super) const fn with_month(&self, month: u32) -> Option<Mdf>
sourcepub(super) const fn with_flags(&self, YearFlags: YearFlags) -> Mdf
pub(super) const fn with_flags(&self, YearFlags: YearFlags) -> Mdf
Replaces the flags of this Mdf
, keeping the month and day.
sourcepub(super) const fn ordinal(&self) -> Option<u32>
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.
sourcepub(super) const fn year_flags(&self) -> YearFlags
pub(super) const fn year_flags(&self) -> YearFlags
Returns the year flags of this Mdf
.
sourcepub(super) const fn ordinal_and_flags(&self) -> Option<i32>
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 PartialOrd for Mdf
impl PartialOrd for Mdf
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more