From 38b1e62b60843a94d5f62062562a01c6cd4ee001 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 8 Feb 2024 21:58:22 -0500 Subject: [PATCH] Add the ability to edit the time on a time_distance record --- .../app/src/components/time_distance.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fitnesstrax/app/src/components/time_distance.rs b/fitnesstrax/app/src/components/time_distance.rs index 7b800c1..e42698f 100644 --- a/fitnesstrax/app/src/components/time_distance.rs +++ b/fitnesstrax/app/src/components/time_distance.rs @@ -25,7 +25,7 @@ use dimensioned::si; use ft_core::{TimeDistance, TimeDistanceActivity}; use glib::Object; use gtk::{prelude::*, subclass::prelude::*}; -use std::{rc::Rc, cell::RefCell}; +use std::{cell::RefCell, rc::Rc}; pub fn time_distance_summary( distance: DistanceFormatter, @@ -202,8 +202,20 @@ impl TimeDistanceEdit { s } - fn update_time(&self, _time: Option) { - unimplemented!() + fn update_time(&self, time: Option) { + if let Some(time_formatter) = time { + let mut workout = self.imp().workout.borrow_mut(); + let tz = workout.datetime.timezone(); + let new_time = workout + .datetime + .date_naive() + .and_time(*time_formatter) + .and_local_timezone(tz) + .unwrap() + .fixed_offset(); + workout.datetime = new_time; + (self.imp().on_update.borrow())(workout.clone()); + } } fn update_distance(&self, distance: Option) {