From 59e71127ed1289b27d167d3bd87694a074506454 Mon Sep 17 00:00:00 2001 From: Andrew Nichols Date: Mon, 9 Mar 2026 20:34:40 -0400 Subject: [PATCH] bug-fix: fix the total time sent in the FIT session --- src/record.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/record.rs b/src/record.rs index 969f4b3..6cef7d7 100644 --- a/src/record.rs +++ b/src/record.rs @@ -118,14 +118,27 @@ fn get_session(start: DateTime, end: DateTime, distance: u32) -> m let mut session = mesgdef::Session::new(); session.timestamp = to_fit_datetime(start); session.start_time = to_fit_datetime(start); - session.total_elapsed_time = (end.timestamp() - start.timestamp()) as u32; - session.total_timer_time = (end.timestamp() - start.timestamp()) as u32; + session.total_elapsed_time = ((end.timestamp() - start.timestamp()) * 1000) as u32; + session.total_timer_time = ((end.timestamp() - start.timestamp()) * 1000) as u32; session.sport = Sport::CYCLING; session.sub_sport = SubSport::INDOOR_CYCLING; session.total_distance = distance; session } +#[test] +fn test_session() { + use chrono::TimeDelta; + + let start = Local::now(); + let delta = TimeDelta::hours(1); + let end = start + delta; + + let actual = get_session(start, end, 0); + assert_eq!(actual.total_elapsed_time, 60 * 60 * 1000); + assert_eq!(actual.total_timer_time, 60 * 60 * 1000); +} + fn get_activity(start: DateTime) -> mesgdef::Activity { let mut activity = mesgdef::Activity::new(); activity.timestamp = to_fit_datetime(start);