rinex/navigation/time/
mod.rs1#[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#[derive(Debug, Clone, PartialEq, PartialOrd)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct TimeOffset {
16 pub lhs: TimeScale,
18
19 pub rhs: TimeScale,
21
22 pub t_ref: (u32, u64),
24
25 pub utc: Option<String>,
27
28 pub polynomial: (f64, f64, f64),
30}
31
32impl TimeOffset {
33 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 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 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}