Skip to content

Commit c4a6589

Browse files
committed
make timestamp pad and use seconds correctly
1 parent af91536 commit c4a6589

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

swiftnav/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ thiserror = "2.0.17"
2020
[dev-dependencies]
2121
float_eq = "1.0.1"
2222
proptest = "1.9.0"
23+
nmea = "0.7"
2324

2425
# This tells docs.rs to include the katex header for math formatting
2526
# To do this locally

swiftnav/src/nmea/gga.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl GGA {
117117
let second = f64::from(self.time.second());
118118
let second_fracs = f64::from(self.time.nanosecond()) / 1_000_000_000.0;
119119

120-
let timestamp = format!("{hour}{minute}{:.2}", second + second_fracs);
120+
let timestamp = format!("{hour:0>2}{minute:0>2}{:05.2}", second + second_fracs);
121121

122122
let (lat_deg, lat_mins) = self.llh.latitude_degree_decimal_minutes();
123123
let lat_hemisphere = self.llh.latitudinal_hemisphere();
@@ -165,6 +165,27 @@ impl GGA {
165165
mod test {
166166
use super::*;
167167

168+
#[test]
169+
fn nmea_crate_can_parse_gga_sentence() {
170+
let gga = GGA::builder()
171+
.sat_in_use(12)
172+
.time(DateTime::from_timestamp(1_761_351_489, 89_999_999).unwrap())
173+
.gps_quality(GPSQuality::SPS)
174+
.hdop(0.9)
175+
.llh(super::LLHDegrees::new(37.7749, -122.4194, 10.0))
176+
.build();
177+
178+
let parse_result = ::nmea::parse_str(dbg!(&gga.to_sentence().as_str()))
179+
.expect("Failed to parse GGA sentence");
180+
181+
let ::nmea::ParseResult::GGA(parsed_gga) = parse_result else {
182+
panic!("Parsed result is not a GGA sentence");
183+
};
184+
185+
assert_eq!(parsed_gga.latitude.unwrap(), 37.7749);
186+
assert_eq!(parsed_gga.longitude.unwrap(), -122.4194);
187+
}
188+
168189
#[test]
169190
fn gga_can_be_turned_into_an_nmea_sentence() {
170191
let gga = GGA::builder()

0 commit comments

Comments
 (0)