From fab339fdd6d997c989ec5b5e0a9049c048c202b3 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Fri, 11 Aug 2023 07:33:20 +0200 Subject: [PATCH] Remove `NaiveDate::with_of` --- src/naive/date.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/naive/date.rs b/src/naive/date.rs index 721afd9e4a..432d11d531 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -38,7 +38,7 @@ use crate::naive::{IsoWeek, NaiveDateTime, NaiveTime}; use crate::{expect, try_opt}; use crate::{Datelike, Weekday}; -use super::internals::{self, Mdf, Of, YearFlags}; +use super::internals::{self, Mdf, YearFlags}; /// A week represented by a [`NaiveDate`] and a [`Weekday`] which is the first /// day of the week. @@ -1052,16 +1052,13 @@ impl NaiveDate { /// Returns `None` when the resulting `NaiveDate` would be invalid. #[inline] const fn with_mdf(&self, mdf: Mdf) -> Option { - Some(self.with_of(try_opt!(mdf.to_of()))) - } - - /// Makes a new `NaiveDate` with the packed ordinal-flags changed. - /// - /// Returns `None` when the resulting `NaiveDate` would be invalid. - /// Does not check if the year flags match the year. - #[inline] - const fn with_of(&self, of: Of) -> NaiveDate { - NaiveDate { yof: (self.yof & !0b1_1111_1111_1111) | of.inner() as i32 } + debug_assert!(self.year_flags().0 == mdf.year_flags().0); + match mdf.ordinal() { + Some(ordinal) => { + Some(NaiveDate { yof: (self.yof & !ORDINAL_MASK) | (ordinal << 4) as i32 }) + } + None => None, // Non-existing date + } } /// Makes a new `NaiveDate` for the next calendar date.