time::macros

Macro datetime

source
datetime!() { /* proc-macro */ }
Expand description

Construct a PrimitiveDateTime or OffsetDateTime with a statically known value.

The resulting expression can be used in const or static declarations.

The syntax accepted by this macro is the same as date! and time!, with an optional offset!, all space-separated. If an offset! is provided, the resulting value will be an OffsetDateTime; otherwise it will be a PrimitiveDateTime.

assert_eq!(
    datetime!(2020-01-01 0:00),
    Date::from_calendar_date(2020, Month::January, 1)?.midnight()
);
assert_eq!(
    datetime!(2020-01-01 0:00 UTC),
    Date::from_calendar_date(2020, Month::January, 1)?.midnight().assume_utc()
);
assert_eq!(
    datetime!(2020-01-01 0:00 -1),
    Date::from_calendar_date(2020, Month::January, 1)?.midnight()
        .assume_offset(UtcOffset::from_hms(-1, 0, 0)?)
);