Remove Of::pred

This commit is contained in:
Paul Dicker 2023-08-10 16:58:09 +02:00 committed by Paul Dicker
parent 1835cfcde2
commit dd873d25df
2 changed files with 4 additions and 15 deletions

View File

@ -1135,9 +1135,10 @@ impl NaiveDate {
#[inline] #[inline]
#[must_use] #[must_use]
pub const fn pred_opt(&self) -> Option<NaiveDate> { pub const fn pred_opt(&self) -> Option<NaiveDate> {
match self.of().pred() { let new_shifted_ordinal = (self.yof & ORDINAL_MASK) - (1 << 4);
Some(of) => Some(self.with_of(of)), match new_shifted_ordinal > 0 {
None => NaiveDate::from_ymd_opt(self.year() - 1, 12, 31), true => Some(NaiveDate { yof: self.yof & !ORDINAL_MASK | new_shifted_ordinal }),
false => NaiveDate::from_ymd_opt(self.year() - 1, 12, 31),
} }
} }

View File

@ -345,15 +345,6 @@ impl Of {
pub(super) const fn to_mdf(&self) -> Mdf { pub(super) const fn to_mdf(&self) -> Mdf {
Mdf::from_of(*self) Mdf::from_of(*self)
} }
/// Returns an `Of` with the previous day, or `None` if this is the first day of the year.
#[inline]
pub(super) const fn pred(&self) -> Option<Of> {
match self.ordinal() {
1 => None,
_ => Some(Of(self.0 - (1 << 4))),
}
}
} }
impl fmt::Debug for Of { impl fmt::Debug for Of {
@ -859,9 +850,6 @@ mod tests {
assert!(Of::from_mdf(Mdf::new(2, 29, regular_year).unwrap()).is_none()); assert!(Of::from_mdf(Mdf::new(2, 29, regular_year).unwrap()).is_none());
assert!(Of::from_mdf(Mdf::new(2, 29, leap_year).unwrap()).is_some()); assert!(Of::from_mdf(Mdf::new(2, 29, leap_year).unwrap()).is_some());
assert!(Of::from_mdf(Mdf::new(2, 28, regular_year).unwrap()).is_some()); assert!(Of::from_mdf(Mdf::new(2, 28, regular_year).unwrap()).is_some());
assert!(Of::new(1, regular_year).unwrap().pred().is_none());
assert!(Of::new(1, leap_year).unwrap().pred().is_none());
} }
#[test] #[test]