#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::prelude::{Epoch, TimeScale};
use hifitime::{Duration, Polynomial};
pub(crate) mod formatting;
pub(crate) mod parsing;
#[cfg(feature = "ublox")]
#[cfg_attr(docsrs, doc(cfg(feature = "ublox")))]
pub mod ublox;
#[derive(Debug, Clone, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TimeOffset {
pub lhs: TimeScale,
pub rhs: TimeScale,
pub t_ref: (u32, u64),
pub utc: Option<String>,
pub polynomial: (f64, f64, f64),
}
impl TimeOffset {
pub fn from_epoch(
t_ref: Epoch,
lhs: TimeScale,
rhs: TimeScale,
polynomial: (f64, f64, f64),
) -> Self {
let t_ref = t_ref.to_time_scale(lhs).to_time_of_week();
Self {
lhs,
rhs,
t_ref,
utc: None,
polynomial,
}
}
pub fn from_time_of_week(
t_week: u32,
t_nanos: u64,
lhs: TimeScale,
rhs: TimeScale,
polynomial: (f64, f64, f64),
) -> Self {
Self {
lhs,
rhs,
utc: None,
polynomial,
t_ref: (t_week, t_nanos),
}
}
pub(crate) fn to_hifitime_polynomial(&self) -> Polynomial {
Polynomial {
constant: Duration::from_seconds(self.polynomial.0),
rate: Duration::from_seconds(self.polynomial.1),
accel: Duration::from_seconds(self.polynomial.2),
}
}
}