From 4bceeb5d747ff9f68ff8dd0e3a604da6ec4325a3 Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Wed, 5 Jul 2023 14:21:20 -0600 Subject: [PATCH] const from_ymd_opt --- src/naive/date.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/naive/date.rs b/src/naive/date.rs index d4d6b662e2..3acbc1fe03 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -285,9 +285,14 @@ impl NaiveDate { /// assert!(from_ymd_opt(-400000, 1, 1).is_none()); /// ``` #[must_use] - pub fn from_ymd_opt(year: i32, month: u32, day: u32) -> Option { + pub const fn from_ymd_opt(year: i32, month: u32, day: u32) -> Option { let flags = YearFlags::from_year(year); - NaiveDate::from_mdf(year, Mdf::new(month, day, flags)?) + + if let Some(mdf) = Mdf::new(month, day, flags) { + NaiveDate::from_mdf(year, mdf) + } else { + None + } } /// Makes a new `NaiveDate` from the [ordinal date](#ordinal-date)