Skip to main content

from_jd

Macro from_jd 

Source
macro_rules! from_jd {
    ($jd_days:expr, $frac:expr, on=$scale:expr) => { ... };
    ($jd_days:expr, on=$scale:expr) => { ... };
    ($jd_days:expr, $frac:expr) => { ... };
    ($jd_days:expr) => { ... };
}
Expand description

Builds a TAI Dt from a Julian Date (whole days plus optional attosecond remainder).

Equivalent to Dt::from_jd.

When an on arg is provided and it’s not Scale::TAI then a time scale conversion is performed equivalent to on -> Scale::TAI.

There is no target= on this macro — the returned Dt’s target is set from on (or TAI when omitted), as from_jd does. Chain .target(…) if needed.

The fractional remainder is in attoseconds — use a *_to_attos helper (e.g. a day fraction built from days_f!) instead of hand-counting zeros when convenient.

§Defaults

OmittedDefault
fraction0
onScale::TAI

§Forms

from_jd!(jd_days)
from_jd!(jd_days, frac)
from_jd!(jd_days, on=s)
from_jd!(jd_days, frac, on=s)

§Examples

use deep_time::{Dt, Scale, days_f, macros::from_jd};

// 2_460_782.25
let a = from_jd!(2_460_782);
let b = from_jd!(2_460_782, days_f!(0.25));
let c = from_jd!(2_460_782, days_f!(0.25), on=Scale::TAI);
let d = from_jd!(2_460_782, on=Scale::UTC);

assert_eq!(a, Dt::from_jd(2_460_782, 0, Scale::TAI));
assert_eq!(b, Dt::from_jd(2_460_782, days_f!(0.25), Scale::TAI));
assert_eq!(c, b);
assert_eq!(d, Dt::from_jd(2_460_782, 0, Scale::UTC));

// -1_000.25 (signed remainder)
let neg = from_jd!(-1_000, -days_f!(0.25));
assert_eq!(neg, Dt::from_jd(-1_000, -days_f!(0.25), Scale::TAI));
assert_eq!(neg.to_jd(), (-1_000, -days_f!(0.25)));

// or with floor style
assert_eq!(neg, from_jd!(-1_001, days_f!(0.75)));