macro_rules! from_ymd {
($y:expr, $m:expr, $d:expr; $h:expr, $min:expr, $s:expr, $attos:expr, on=$scale:expr) => { ... };
($y:expr, $m:expr, $d:expr; $h:expr, $min:expr, $s:expr, on=$scale:expr) => { ... };
($y:expr, $m:expr, $d:expr; $h:expr, $min:expr, on=$scale:expr) => { ... };
($y:expr, $m:expr, $d:expr; $h:expr, on=$scale:expr) => { ... };
($y:expr, $m:expr, $d:expr; $h:expr, $min:expr, $s:expr, $attos:expr) => { ... };
($y:expr, $m:expr, $d:expr; $h:expr, $min:expr, $s:expr) => { ... };
($y:expr, $m:expr, $d:expr; $h:expr, $min:expr) => { ... };
($y:expr, $m:expr, $d:expr; $h:expr) => { ... };
($y:expr, $m:expr, $d:expr, on=$scale:expr) => { ... };
($y:expr, $m:expr, on=$scale:expr) => { ... };
($y:expr, on=$scale:expr) => { ... };
($y:expr, $m:expr, $d:expr) => { ... };
($y:expr, $m:expr) => { ... };
($y:expr) => { ... };
}Expand description
Builds a Dt from a Gregorian calendar date and optional time.
Sugar for Dt::from_ymd.
Date fields are positional (y, m, d). Time is optional: put a
semicolon after the day, then hour (required if ; is present), then
optional minute, second, and attoseconds. An optional on= civil scale may
follow.
| Omitted field | Default |
|---|---|
| month | 1 |
| day | 1 |
time (no ;) | 0, 0, 0, 0 |
minute / second / attos after ; h | 0 |
on | Scale::UTC |
The resulting Dt’s target field is set from that civil
scale (the on= value, or UTC when omitted), as
from_ymd does. There is no target= on
this macro — chain .target(…) if needed.
§Forms
from_ymd!(y)
from_ymd!(y, m)
from_ymd!(y, m, d)
from_ymd!(y, m, d, on=Scale::TAI)
from_ymd!(y, m, d; h)
from_ymd!(y, m, d; h, min)
from_ymd!(y, m, d; h, min, sec)
from_ymd!(y, m, d; h, min, sec, attos)
from_ymd!(y, m, d; h, min, sec, attos, on=Scale::UTC)§Examples
use deep_time::Scale;
use deep_time::from_ymd;
assert_eq!(
from_ymd!(1970),
deep_time::Dt::UNIX_EPOCH,
);
assert_eq!(
from_ymd!(2026, 6, 16),
deep_time::Dt::from_ymd(2026, 6, 16, Scale::UTC, 0, 0, 0, 0),
);
assert_eq!(
from_ymd!(2000, 1, 1; 12, on=Scale::TAI),
deep_time::Dt::ZERO,
);
assert_eq!(
from_ymd!(2000, 1, 1; 12, 0, 0, 123_456_789, on=Scale::UTC),
deep_time::Dt::from_ymd(2000, 1, 1, Scale::UTC, 12, 0, 0, 123_456_789),
);
// different target field after construction
let _ = from_ymd!(2020, 1, 1, on=Scale::UTC).target(Scale::TAI);