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]
#[must_use]
pub const fn pred_opt(&self) -> Option<NaiveDate> {
match self.of().pred() {
Some(of) => Some(self.with_of(of)),
None => NaiveDate::from_ymd_opt(self.year() - 1, 12, 31),
let new_shifted_ordinal = (self.yof & ORDINAL_MASK) - (1 << 4);
match new_shifted_ordinal > 0 {
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 {
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 {
@ -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, leap_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]