Remove DateImpl type alias

This commit is contained in:
Paul Dicker 2023-08-11 13:59:34 +02:00 committed by Paul Dicker
parent 1cebe0cfda
commit ca10fea322
3 changed files with 12 additions and 15 deletions

View File

@ -27,7 +27,7 @@ use crate::naive::{IsoWeek, NaiveDateTime, NaiveTime};
use crate::{expect, try_opt};
use crate::{Datelike, TimeDelta, Weekday};
use super::internals::{self, DateImpl, Mdf, Of, YearFlags};
use super::internals::{self, Mdf, Of, YearFlags};
use super::isoweek;
const MAX_YEAR: i32 = internals::MAX_YEAR;
@ -196,7 +196,7 @@ impl Days {
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
pub struct NaiveDate {
ymdf: DateImpl, // (year << 13) | of
ymdf: i32, // (year << 13) | of
}
/// The minimum possible `NaiveDate` (January 1, 262145 BCE).
@ -233,7 +233,7 @@ impl NaiveDate {
}
debug_assert!(YearFlags::from_year(year).0 == flags.0);
match Of::new(ordinal, flags) {
Some(of) => Some(NaiveDate { ymdf: (year << 13) | (of.inner() as DateImpl) }),
Some(of) => Some(NaiveDate { ymdf: (year << 13) | (of.inner() as i32) }),
None => None, // Invalid: Ordinal outside of the nr of days in a year with those flags.
}
}
@ -245,7 +245,7 @@ impl NaiveDate {
return None; // Out-of-range
}
match mdf.to_of() {
Some(of) => Some(NaiveDate { ymdf: (year << 13) | (of.inner() as DateImpl) }),
Some(of) => Some(NaiveDate { ymdf: (year << 13) | (of.inner() as i32) }),
None => None, // Non-existing date
}
}
@ -1058,7 +1058,7 @@ impl NaiveDate {
/// Does not check if the year flags match the year.
#[inline]
const fn with_of(&self, of: Of) -> NaiveDate {
NaiveDate { ymdf: (self.ymdf & !0b1_1111_1111_1111) | of.inner() as DateImpl }
NaiveDate { ymdf: (self.ymdf & !0b1_1111_1111_1111) | of.inner() as i32 }
}
/// Makes a new `NaiveDate` for the next calendar date.

View File

@ -18,18 +18,15 @@
use crate::Weekday;
use core::fmt;
/// The internal date representation: `year << 13 | Of`
pub(super) type DateImpl = i32;
/// MAX_YEAR is one year less than the type is capable of representing. Internally we may sometimes
/// use the headroom, notably to handle cases where the offset of a `DateTime` constructed with
/// `NaiveDate::MAX` pushes it beyond the valid, representable range.
pub(super) const MAX_YEAR: DateImpl = (i32::MAX >> 13) - 1;
pub(super) const MAX_YEAR: i32 = (i32::MAX >> 13) - 1;
/// MIN_YEAR is one year more than the type is capable of representing. Internally we may sometimes
/// use the headroom, notably to handle cases where the offset of a `DateTime` constructed with
/// `NaiveDate::MIN` pushes it beyond the valid, representable range.
pub(super) const MIN_YEAR: DateImpl = (i32::MIN >> 13) + 1;
pub(super) const MIN_YEAR: i32 = (i32::MIN >> 13) + 1;
/// The year flags (aka the dominical letter).
///
@ -285,8 +282,8 @@ impl Of {
of.validate()
}
pub(super) const fn from_date_impl(date_impl: DateImpl) -> Of {
// We assume the value in the `DateImpl` is valid.
pub(super) const fn from_date_impl(date_impl: i32) -> Of {
// We assume the value in `date_impl` is valid.
Of((date_impl & 0b1_1111_1111_1111) as u32)
}

View File

@ -5,7 +5,7 @@
use core::fmt;
use super::internals::{DateImpl, Of, YearFlags};
use super::internals::{Of, YearFlags};
#[cfg(any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"))]
use rkyv::{Archive, Deserialize, Serialize};
@ -28,7 +28,7 @@ pub struct IsoWeek {
// note that this allows for larger year range than `NaiveDate`.
// this is crucial because we have an edge case for the first and last week supported,
// which year number might not match the calendar year number.
ywf: DateImpl, // (year << 10) | (week << 4) | flag
ywf: i32, // (year << 10) | (week << 4) | flag
}
/// Returns the corresponding `IsoWeek` from the year and the `Of` internal value.
@ -53,7 +53,7 @@ pub(super) fn iso_week_from_yof(year: i32, of: Of) -> IsoWeek {
}
};
let flags = YearFlags::from_year(year);
IsoWeek { ywf: (year << 10) | (week << 4) as DateImpl | DateImpl::from(flags.0) }
IsoWeek { ywf: (year << 10) | (week << 4) as i32 | i32::from(flags.0) }
}
impl IsoWeek {