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:

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

Example

use jiff::civil::DateTime;

let d = DateTime::constant(2024, 2, 29, 21, 30, 5, 123_456_789);
assert_eq!(d.date().year(), 2024);
assert_eq!(d.date().month(), 2);
assert_eq!(d.date().day(), 29);
assert_eq!(d.time().hour(), 21);
assert_eq!(d.time().minute(), 30);
assert_eq!(d.time().second(), 5);
assert_eq!(d.time().millisecond(), 123);
assert_eq!(d.time().microsecond(), 456);
assert_eq!(d.time().nanosecond(), 789);