rinex/navigation/time/
mod.rs

1// NAV V4 System Time Messages
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5use crate::prelude::{Epoch, TimeScale};
6
7use hifitime::{Duration, Polynomial};
8
9pub(crate) mod formatting;
10pub(crate) mod parsing;
11
12/// System Time (offset) Message
13#[derive(Debug, Clone, PartialEq, PartialOrd)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct TimeOffset {
16    /// Left hand side [TimeScale]
17    pub lhs: TimeScale,
18
19    /// Reference [TimeScale]
20    pub rhs: TimeScale,
21
22    /// Reference time expressed as week counter and nanoseconds of week.
23    pub t_ref: (u32, u64),
24
25    /// Possible UTC ID# in case this came from RINEXv4
26    pub utc: Option<String>,
27
28    /// Interpolation polynomial
29    pub polynomial: (f64, f64, f64),
30}
31
32impl TimeOffset {
33    /// Define a new [TimeOffset]
34    pub fn from_epoch(
35        t_ref: Epoch,
36        lhs: TimeScale,
37        rhs: TimeScale,
38        polynomial: (f64, f64, f64),
39    ) -> Self {
40        let t_ref = t_ref.to_time_scale(lhs).to_time_of_week();
41        Self {
42            lhs,
43            rhs,
44            t_ref,
45            utc: None,
46            polynomial,
47        }
48    }
49
50    /// Define a new [TimeOffset]
51    pub fn from_time_of_week(
52        t_week: u32,
53        t_nanos: u64,
54        lhs: TimeScale,
55        rhs: TimeScale,
56        polynomial: (f64, f64, f64),
57    ) -> Self {
58        Self {
59            lhs,
60            rhs,
61            utc: None,
62            polynomial,
63            t_ref: (t_week, t_nanos),
64        }
65    }
66
67    /// Converts this [TimeOffset] to Hifitime [Polynomial].
68    pub(crate) fn to_hifitime_polynomial(&self) -> Polynomial {
69        Polynomial {
70            constant: Duration::from_seconds(self.polynomial.0),
71            rate: Duration::from_seconds(self.polynomial.1),
72            accel: Duration::from_seconds(self.polynomial.2),
73        }
74    }
75}