Skip to main content

lox_frames/
providers.rs

1// SPDX-FileCopyrightText: 2025 Helge Eichhorn <git@helgeeichhorn.de>
2//
3// SPDX-License-Identifier: MPL-2.0
4
5use std::convert::Infallible;
6
7use lox_time::{
8    Time,
9    deltas::TimeDelta,
10    offsets::OffsetProvider,
11    time_scales::{ContinuousTimeScale, Tai},
12    utc::{
13        Utc,
14        leap_seconds::{DefaultLeapSecondsProvider, LeapSecondsProvider},
15    },
16};
17
18use crate::{
19    iers::{Corrections, ReferenceSystem, polar_motion::PoleCoords},
20    rotations::RotationProvider,
21};
22
23/// Default rotation provider with no EOP data (zero corrections, zero polar motion).
24#[derive(Copy, Clone, Debug)]
25pub struct DefaultRotationProvider;
26
27impl OffsetProvider for DefaultRotationProvider {
28    type Error = Infallible;
29
30    fn tai_to_ut1(&self, delta: TimeDelta) -> Result<TimeDelta, Self::Error> {
31        // UT1 is approximated by UTC, which is good to |UT1 - UTC| <= 0.9 s.
32        // The contract is the offset *to* the target scale, i.e. UT1 - TAI,
33        // so the leap-second count (TAI - UTC) has to be negated.
34        let tai = Time::from_delta(Tai, delta);
35        Ok(-DefaultLeapSecondsProvider.delta_tai_utc(tai))
36    }
37
38    fn ut1_to_tai(&self, delta: TimeDelta) -> Result<TimeDelta, Self::Error> {
39        let utc = Utc::from_delta(delta);
40        Ok(-DefaultLeapSecondsProvider.delta_utc_tai(utc))
41    }
42}
43
44impl<T> RotationProvider<T> for DefaultRotationProvider
45where
46    T: ContinuousTimeScale,
47{
48    type EopError = Infallible;
49
50    fn corrections(
51        &self,
52        _time: Time<T>,
53        _sys: ReferenceSystem,
54    ) -> Result<Corrections, Self::EopError> {
55        Ok(Corrections::default())
56    }
57
58    fn pole_coords(&self, _time: Time<T>) -> Result<PoleCoords, Self::EopError> {
59        Ok(PoleCoords::default())
60    }
61}