Skip to main content

deep_time/dt/
epoch.rs

1use crate::{Dt, Scale, TSpan};
2
3impl Dt {
4    #[inline]
5    pub const fn to_tai_attos_since(self, reference: Dt) -> i128 {
6        self.to_tai_since(reference).to_attos()
7    }
8
9    #[inline]
10    pub const fn from_tai_attos_since(attos: i128, reference: Dt) -> Self {
11        reference.add(TSpan::from_attos(attos))
12    }
13
14    #[inline]
15    pub const fn to_epoch(self, epoch: Dt, scale: Scale) -> TSpan {
16        /*
17        do not apply an offset using to() to the EPOCH because the offset is for TAI,
18        the to() function assumes the epoch is TAI, the UTCSofa instant for 1970 is
19        the same as the UTC instant UNIX_EPOCH should remain UTC and the offset should
20        not be applied to the epoch
21        */
22        self.to(scale).to_diff_tp(epoch)
23    }
24
25    #[inline]
26    pub const fn from_epoch(offset: TSpan, epoch: Dt, scale: Scale) -> Self {
27        let total = epoch.to_span().add(offset);
28        Dt::from(total.sec, total.attos, scale)
29    }
30}