devela::_dep::jiff::civil

Function date

pub const fn date(year: i16, month: i8, day: i8) -> Date
Available on crate features dep_jiff and alloc only.
Expand description

Creates a new Date value in a const context.

This is a convenience free function for Date::constant. It is intended to provide a terse syntax for constructing Date values from parameters that are known to be valid.

§Panics

This routine panics when Date::new would return an error. That is, when the given year-month-day does not correspond to a valid date. Namely, all of the following must be true:

  • The year must be in the range -9999..=9999.
  • The month must be in the range 1..=12.
  • The day must be at least 1 and must be at most the number of days in the corresponding month. So for example, 2024-02-29 is valid but 2023-02-29 is not.

Similarly, when used in a const context, invalid parameters will prevent your Rust program from compiling.

§Example

use jiff::civil::date;

let d = date(2024, 2, 29);
assert_eq!(d.year(), 2024);
assert_eq!(d.month(), 2);
assert_eq!(d.day(), 29);