Skip to main content

deep_time/dt/
from_gps.rs

1use crate::{ATTOS_PER_WEEK, Real, Dt, TSpan};
2
3impl Dt {
4    /// Creates a `Dt` in GPS Time (GPS) from a GPS week number and
5    /// Time of Week (TOW).
6    ///
7    /// This is the exact inverse of [`Self::to_gps_week_and_tow`].
8    ///
9    /// - `week`: Full GPS week number (can be negative for dates before 1980).
10    /// - `tow`: Time of Week as a [`TSpan`]. Values ≥ 604800 seconds are
11    ///   automatically carried into the week number.
12    ///
13    /// The resulting `Dt` is always in `Scale::GPS`.
14    #[inline]
15    pub const fn from_gps_wk_and_tow(wk: i64, tow: TSpan) -> Self {
16        let total_attos = (wk as i128) * ATTOS_PER_WEEK + tow.to_attos();
17        Self::GPS_EPOCH.add(TSpan::from_attos(total_attos))
18    }
19
20    /// Creates a `Dt` in GPS Time from a GPS week number and
21    /// floating-point Time of Week.
22    ///
23    /// This is the floating-point counterpart to [`Self::from_gps_wk_and_tow`].
24    #[inline]
25    pub const fn from_gps_wk_and_tow_f(week: i64, tow: Real) -> Self {
26        let tow_span = TSpan::from_sec_f(tow);
27        Self::from_gps_wk_and_tow(week, tow_span)
28    }
29}