pub const fn date(year: i16, month: i8, day: i8) -> DateExpand 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
1and must be at most the number of days in the corresponding month. So for example,2024-02-29is valid but2023-02-29is 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);