Skip to main content

from_ms

Macro from_ms 

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

Builds a Dt from whole milliseconds and an optional signed fractional remainder in attoseconds.

Sugar for Dt::from_ms. Does not perform time-scale conversion.

The fractional remainder is in attoseconds — use us! (or another *_to_attos helper) instead of writing the attosecond literal by hand.

§Defaults

OmittedDefault
fraction0
on and targetboth Scale::TAI
only on=starget=s
only target=ton=TAI

§Forms

from_ms!(ms)
from_ms!(ms, frac)
from_ms!(ms, on=s)
from_ms!(ms, target=t)
from_ms!(ms, on=s, target=t)
from_ms!(ms, target=t, on=s)
from_ms!(ms, frac, on=s)
from_ms!(ms, frac, target=t)
from_ms!(ms, frac, on=s, target=t)
from_ms!(ms, frac, target=t, on=s)

§Examples

use deep_time::{Dt, Scale, from_ms, us};

// 1.3 ms → whole milliseconds + 300 µs remainder
let a = from_ms!(1);
let b = from_ms!(1, us!(300));
let c = from_ms!(-1, us!(-300), on=Scale::TAI);
let d = from_ms!(0, on=Scale::UTC);
let e = from_ms!(1, on=Scale::TAI, target=Scale::UTC);
let f = from_ms!(1, target=Scale::UTC);

assert_eq!(a, Dt::from_ms(1, 0, Scale::TAI, Scale::TAI));
assert_eq!(b, Dt::from_ms(1, us!(300), Scale::TAI, Scale::TAI));
assert_eq!(c, Dt::from_ms(-1, us!(-300), Scale::TAI, Scale::TAI));
assert_eq!(d, Dt::from_ms(0, 0, Scale::UTC, Scale::UTC));
assert_eq!(e, Dt::from_ms(1, 0, Scale::TAI, Scale::UTC));
assert_eq!(f, e);

let signed = from_ms!(-1, us!(-300));
let floor = from_ms!(-2, us!(700));
assert_eq!(signed, floor);
assert_eq!(signed, Dt::from_ms(-1, us!(-300), Scale::TAI, Scale::TAI));