Skip to content

Commit

Permalink
const from_ymd_opt
Browse files Browse the repository at this point in the history
  • Loading branch information
kamadorueda committed Jul 6, 2023
1 parent ac80252 commit 4bceeb5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NaiveDate> {
pub const fn from_ymd_opt(year: i32, month: u32, day: u32) -> Option<NaiveDate> {
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)
Expand Down

0 comments on commit 4bceeb5

Please sign in to comment.