time::macros

Macro time

Source
time!() { /* proc-macro */ }
Available on crate feature macros only.
Expand description

Construct a Time with a statically known value.

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

Hours and minutes must be provided, while seconds defaults to zero. AM/PM is allowed (either uppercase or lowercase). Any number of subsecond digits may be provided (though any past nine will be discarded).

All components are validated at compile-time. An error will be raised if any value is invalid.

assert_eq!(time!(0:00), Time::from_hms(0, 0, 0)?);
assert_eq!(time!(1:02:03), Time::from_hms(1, 2, 3)?);
assert_eq!(
    time!(1:02:03.004_005_006),
    Time::from_hms_nano(1, 2, 3, 4_005_006)?
);
assert_eq!(time!(12:00 am), Time::from_hms(0, 0, 0)?);
assert_eq!(time!(1:02:03 am), Time::from_hms(1, 2, 3)?);
assert_eq!(
    time!(1:02:03.004_005_006 am),
    Time::from_hms_nano(1, 2, 3, 4_005_006)?
);
assert_eq!(time!(12 pm), Time::from_hms(12, 0, 0)?);
assert_eq!(time!(12:00 pm), Time::from_hms(12, 0, 0)?);
assert_eq!(time!(1:02:03 pm), Time::from_hms(13, 2, 3)?);
assert_eq!(
    time!(1:02:03.004_005_006 pm),
    Time::from_hms_nano(13, 2, 3, 4_005_006)?
);