macro_rules! time {
($($proc_macro:tt)*) => { ... };
}
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::try_from_hms(0, 0, 0)?);
assert_eq!(time!(1:02:03), Time::try_from_hms(1, 2, 3)?);
assert_eq!(time!(1:02:03.004_005_006), Time::try_from_hms_nano(1, 2, 3, 4_005_006)?);
assert_eq!(time!(12:00 am), Time::try_from_hms(0, 0, 0)?);
assert_eq!(time!(1:02:03 am), Time::try_from_hms(1, 2, 3)?);
assert_eq!(time!(1:02:03.004_005_006 am), Time::try_from_hms_nano(1, 2, 3, 4_005_006)?);
assert_eq!(time!(12:00 pm), Time::try_from_hms(12, 0, 0)?);
assert_eq!(time!(1:02:03 pm), Time::try_from_hms(13, 2, 3)?);
assert_eq!(time!(1:02:03.004_005_006 pm), Time::try_from_hms_nano(13, 2, 3, 4_005_006)?);