handle corrupt time data

This commit is contained in:
vcoppe committed 2026-10-08 08:59:53 +02:00
1 parent f0851086c0
commit e8c4eb92f9
2 files changed
+47 -3

No files matched your search

@@ -283,13 +283,18 @@ pub struct GlobalStatistics {
}
impl GlobalStatistics {
/// Average speed over the total time, unknown if that is not a positive duration (for
/// example a range with a single timestamp, or timestamps going backwards).
pub fn total_speed(&self) -> Option<f64> {
self.total_time.map(|t| speed(self.total_distance, t))
self.total_time
.filter(|t| *t > 0)
.map(|t| speed(self.total_distance, t))
}
/// Average speed over the moving time, unknown if there is no moving time.
pub fn moving_speed(&self) -> Option<f64> {
self.moving_distance
.zip(self.moving_time)
.zip(self.moving_time.filter(|t| *t > 0))
.map(|(d, t)| speed(d, t))
}