attotime/time_scale/
gpst.rs1use crate::{
4 Date, Duration, FromTimeScale, IntoTimeScale, Month, TerrestrialTime, TimePoint,
5 UniformDateTimeScale,
6 time_scale::{AbsoluteTimeScale, TimeScale},
7};
8
9pub type GpsTime = TimePoint<Gpst>;
10
11#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
15pub struct Gpst;
16
17impl TimeScale for Gpst {
18 const NAME: &'static str = "Global Positioning System Time";
19
20 const ABBREVIATION: &'static str = "GPST";
21}
22
23impl AbsoluteTimeScale for Gpst {
24 const EPOCH: Date = match Date::from_historic_date(1980, Month::January, 6) {
25 Ok(epoch) => epoch,
26 Err(_) => unreachable!(),
27 };
28}
29
30impl UniformDateTimeScale for Gpst {}
31
32impl<Scale: ?Sized> TimePoint<Scale> {
33 pub fn from_gpst(time_point: GpsTime) -> Self
34 where
35 Self: FromTimeScale<Gpst>,
36 {
37 Self::from_time_scale(time_point)
38 }
39
40 pub fn into_gpst(self) -> GpsTime
41 where
42 Self: IntoTimeScale<Gpst>,
43 {
44 self.into_time_scale()
45 }
46}
47
48impl TerrestrialTime for Gpst {
49 const TAI_OFFSET: Duration = Duration::seconds(-19);
50}
51
52#[test]
55fn known_timestamps() {
56 use crate::TaiTime;
57 let tai = TaiTime::from_historic_datetime(2004, Month::May, 14, 16, 43, 32).unwrap();
58 let gpst = GpsTime::from_historic_datetime(2004, Month::May, 14, 16, 43, 13).unwrap();
59 assert_eq!(tai, gpst.into_tai());
60}