#[cfg(feature = "python")]
use pyo3::prelude::*;
#[cfg(feature = "std")]
pub use super::leap_seconds_file::LeapSecondsFile;
use core::ops::Index;
pub trait LeapSecondProvider: DoubleEndedIterator<Item = LeapSecond> + Index<usize> {}
#[repr(C)]
#[cfg_attr(feature = "python", pyclass)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct LeapSecond {
pub timestamp_tai_s: f64,
pub delta_at: f64,
pub announced_by_iers: bool,
}
impl LeapSecond {
pub const fn new(timestamp_tai_s: f64, delta_at: f64, announced: bool) -> Self {
Self {
timestamp_tai_s,
delta_at,
announced_by_iers: announced,
}
}
}
const LATEST_LEAP_SECONDS: [LeapSecond; 42] = [
LeapSecond::new(1_893_369_600.0, 1.417818, false), LeapSecond::new(1_924_992_000.0, 1.422818, false), LeapSecond::new(1_943_308_800.0, 1.372818, false), LeapSecond::new(1_956_528_000.0, 1.845858, false), LeapSecond::new(2_014_329_600.0, 1.945858, false), LeapSecond::new(2_019_600_000.0, 3.24013, false), LeapSecond::new(2_027_462_400.0, 3.34013, false), LeapSecond::new(2_040_681_600.0, 3.44013, false), LeapSecond::new(2_051_222_400.0, 3.54013, false), LeapSecond::new(2_056_320_000.0, 3.64013, false), LeapSecond::new(2_066_860_800.0, 3.74013, false), LeapSecond::new(2_072_217_600.0, 3.84013, false), LeapSecond::new(2_082_758_400.0, 4.31317, false), LeapSecond::new(2_148_508_800.0, 4.21317, false), LeapSecond::new(2_272_060_800.0, 10.0, true), LeapSecond::new(2_287_785_600.0, 11.0, true), LeapSecond::new(2_303_683_200.0, 12.0, true), LeapSecond::new(2_335_219_200.0, 13.0, true), LeapSecond::new(2_366_755_200.0, 14.0, true), LeapSecond::new(2_398_291_200.0, 15.0, true), LeapSecond::new(2_429_913_600.0, 16.0, true), LeapSecond::new(2_461_449_600.0, 17.0, true), LeapSecond::new(2_492_985_600.0, 18.0, true), LeapSecond::new(2_524_521_600.0, 19.0, true), LeapSecond::new(2_571_782_400.0, 20.0, true), LeapSecond::new(2_603_318_400.0, 21.0, true), LeapSecond::new(2_634_854_400.0, 22.0, true), LeapSecond::new(2_698_012_800.0, 23.0, true), LeapSecond::new(2_776_982_400.0, 24.0, true), LeapSecond::new(2_840_140_800.0, 25.0, true), LeapSecond::new(2_871_676_800.0, 26.0, true), LeapSecond::new(2_918_937_600.0, 27.0, true), LeapSecond::new(2_950_473_600.0, 28.0, true), LeapSecond::new(2_982_009_600.0, 29.0, true), LeapSecond::new(3_029_443_200.0, 30.0, true), LeapSecond::new(3_076_704_000.0, 31.0, true), LeapSecond::new(3_124_137_600.0, 32.0, true), LeapSecond::new(3_345_062_400.0, 33.0, true), LeapSecond::new(3_439_756_800.0, 34.0, true), LeapSecond::new(3_550_089_600.0, 35.0, true), LeapSecond::new(3_644_697_600.0, 36.0, true), LeapSecond::new(3_692_217_600.0, 37.0, true), ];
#[cfg_attr(feature = "python", pyclass)]
#[derive(Clone, Debug)]
pub struct LatestLeapSeconds {
data: [LeapSecond; 42],
iter_pos: usize,
}
#[cfg(feature = "python")]
#[cfg_attr(feature = "python", pymethods)]
impl LatestLeapSeconds {
#[new]
pub fn __new__() -> Self {
Self::default()
}
fn __repr__(&self) -> String {
format!("{self:?}")
}
}
impl Default for LatestLeapSeconds {
fn default() -> Self {
Self {
data: LATEST_LEAP_SECONDS,
iter_pos: 0,
}
}
}
impl Iterator for LatestLeapSeconds {
type Item = LeapSecond;
fn next(&mut self) -> Option<Self::Item> {
self.iter_pos += 1;
self.data.get(self.iter_pos - 1).copied()
}
}
impl DoubleEndedIterator for LatestLeapSeconds {
fn next_back(&mut self) -> Option<Self::Item> {
if self.iter_pos == self.data.len() {
None
} else {
self.iter_pos += 1;
self.data.get(self.data.len() - self.iter_pos).copied()
}
}
}
impl Index<usize> for LatestLeapSeconds {
type Output = LeapSecond;
fn index(&self, index: usize) -> &Self::Output {
self.data.index(index)
}
}
impl LeapSecondProvider for LatestLeapSeconds {}