@@ -123,6 +123,10 @@ impl GpsTime {
123
123
& self . 0
124
124
}
125
125
126
+ pub ( crate ) fn mut_c_ptr ( & mut self ) -> * mut swiftnav_sys:: gps_time_t {
127
+ & mut self . 0
128
+ }
129
+
126
130
pub ( crate ) fn unknown ( ) -> swiftnav_sys:: gps_time_t {
127
131
swiftnav_sys:: gps_time_t { tow : -1.0 , wn : -1 }
128
132
}
@@ -729,19 +733,27 @@ impl UtcTime {
729
733
)
730
734
}
731
735
736
+ /// Converts the UTC time into GPS time
737
+ pub fn to_gps ( & self , utc_params : & UtcParams ) -> GpsTime {
738
+ let mut gps = GpsTime :: new_unchecked ( 0 , 0.0 ) ;
739
+ unsafe {
740
+ swiftnav_sys:: utc2gps ( self . c_ptr ( ) , gps. mut_c_ptr ( ) , utc_params. c_ptr ( ) ) ;
741
+ }
742
+ gps
743
+ }
744
+
745
+ /// Converts the UTC time into GPS time using the hardcoded list of leap
746
+ /// seconds.
747
+ ///
748
+ /// # ⚠️ 🦘 ⏱ ⚠️ - Leap Seconds
749
+ /// The hard coded list of leap seconds will get out of date, it is
750
+ /// preferable to use [`UtcTime::to_gps()`] with the newest set of UTC parameters
732
751
pub fn to_gps_hardcoded ( & self ) -> GpsTime {
733
- let is_lse = self . seconds ( ) >= 60.0 ;
734
- let mjd = self . to_mjd ( ) ;
735
- let gps = unsafe { swiftnav_sys:: mjd2gps ( mjd. 0 ) } ;
736
- let gps = GpsTime ( gps) ;
737
-
738
- // During a leap second event the MJD is wrong by a second, so remove the
739
- // erroneous second here
740
- if is_lse {
741
- gps - std:: time:: Duration :: from_secs ( 1 )
742
- } else {
743
- gps
752
+ let mut gps = GpsTime :: new_unchecked ( 0 , 0.0 ) ;
753
+ unsafe {
754
+ swiftnav_sys:: utc2gps ( self . c_ptr ( ) , gps. mut_c_ptr ( ) , std:: ptr:: null ( ) ) ;
744
755
}
756
+ gps
745
757
}
746
758
}
747
759
0 commit comments