Skip to content

Commit 0abdb0a

Browse files
committed
Add a function to convert from UTC to GPS
1 parent 4601748 commit 0abdb0a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

swiftnav-sys/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ fn main() {
8383
.allowlist_function("floor_to_epoch")
8484
.allowlist_function("glo2gps")
8585
.allowlist_function("gps2glo")
86+
.allowlist_function("mjd2gps")
8687
.allowlist_var("FLOAT_EQUALITY_EPS")
8788
.allowlist_var("MINUTE_SECS")
8889
.allowlist_var("HOUR_SECS")

swiftnav/src/time.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,21 @@ impl UtcTime {
728728
self.seconds()
729729
)
730730
}
731+
732+
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
744+
}
745+
}
731746
}
732747

733748
impl Default for UtcTime {

0 commit comments

Comments
 (0)