keep waypoint time on import (#409)

* keep waypoint time on import

* Remove extra newline in parse.rs test file

---------

Co-authored-by: vcoppe <vianney.coppe@gmail.com>
This commit is contained in:
Jay Hemnaniandvcoppe authored and GitHub committed 2026-11-15 10:57:06 +01:00
1 parent 58b2861160
commit 8aede444fc
1 file changed
+14 -4
+14 -4
View File
@@ -213,10 +213,13 @@ fn apply_text(
}
Some(GPXElement::Time) => {
stack.pop();
if let Some(GPXElement::Trackpoint(trkpt)) = stack.last_mut() {
trkpt.time = DateTime::parse_from_rfc3339(e)
.ok()
.map(|time| time.timestamp_millis());
let time = DateTime::parse_from_rfc3339(e)
.ok()
.map(|time| time.timestamp_millis());
match stack.last_mut() {
Some(GPXElement::Trackpoint(trkpt)) => trkpt.time = time,
Some(GPXElement::Waypoint(wpt)) => wpt.time = time,
_ => (),
}
}
Some(GPXElement::Temperature) => {
@@ -1143,6 +1146,13 @@ mod tests {
assert!(wpt.type_.as_ref().is_some_and(|t| t == "Bike Trail"));
}
#[test]
fn test_parse_waypoint_time() {
let data = r#"<gpx><wpt lat="1" lon="2"><time>2024-05-01T06:10:00Z</time></wpt></gpx>"#;
let gpx = parse(data.as_bytes(), &mut Default::default()).unwrap();
assert_eq!(gpx.wpt[0].time, Some(1714543800000));
}
#[test]
fn test_parse_trackpoint_time() {
let gpx = parse_data("with_time");