Skip to main content

from_mjd

Macro from_mjd 

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

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

Equivalent to Dt::from_mjd.

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_mjd does. Chain .target(…) if needed.

MJD and JD relate by JD = MJD + 2_400_000.5.

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_mjd!(mjd_days)
from_mjd!(mjd_days, frac)
from_mjd!(mjd_days, on=s)
from_mjd!(mjd_days, frac, on=s)

§Examples

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

// J2000.0 → MJD 51_544.5
let a = from_mjd!(51_544);
let b = from_mjd!(51_544, days_f!(0.5));
let c = from_mjd!(51_544, days_f!(0.5), on=Scale::TAI);
let d = from_mjd!(51_544, on=Scale::UTC);

assert_eq!(a, Dt::from_mjd(51_544, 0, Scale::TAI));
assert_eq!(b, Dt::from_mjd(51_544, days_f!(0.5), Scale::TAI));
assert_eq!(c, b);
assert_eq!(d, Dt::from_mjd(51_544, 0, Scale::UTC));
assert_eq!(b.to_mjd(), (51_544, days_f!(0.5)));

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

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