Function datetime
const fn datetime(year: i16, month: i8, day: i8, hour: i8, minute: i8, second: i8, subsec_nanosecond: i32) -> DateTime
Creates a new DateTime value in a const context.
This is a convenience free function for DateTime::constant. It is
intended to provide a terse syntax for constructing DateTime values from
parameters that are known to be valid.
Panics
This routine panics when DateTime::new would return an error. That
is, when the given components do not correspond to a valid datetime.
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. 0 <= hour <= 230 <= minute <= 590 <= second <= 590 <= subsec_nanosecond <= 999,999,999
Similarly, when used in a const context, invalid parameters will prevent your Rust program from compiling.
Example
use DateTime;
let d = constant;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;