From 6b51fcc0f175d9b5664f84423902466fd1b24fea Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 28 Dec 2023 12:44:42 -0500 Subject: [PATCH] Drop DateTimeTz from fitnesstrax --- fitnesstrax/app/src/app_window.rs | 35 +------------------- fitnesstrax/app/src/views/historical_view.rs | 16 ++++++--- fitnesstrax/core/src/lib.rs | 4 --- fitnesstrax/core/src/types.rs | 10 +++--- 4 files changed, 16 insertions(+), 49 deletions(-) diff --git a/fitnesstrax/app/src/app_window.rs b/fitnesstrax/app/src/app_window.rs index 0326a22..081c755 100644 --- a/fitnesstrax/app/src/app_window.rs +++ b/fitnesstrax/app/src/app_window.rs @@ -23,7 +23,6 @@ use async_channel::Sender; use chrono::{NaiveDate, TimeZone}; use chrono_tz::America::Anchorage; use dimensioned::si::{KG, M, S}; -use emseries::DateTimeTz; use ft_core::{Steps, TimeDistance, TraxRecord, Weight}; use gio::resources_lookup_data; use gtk::STYLE_PROVIDER_PRIORITY_USER; @@ -149,39 +148,7 @@ impl AppWindow { }) .upcast(), ), - ViewName::Historical => View::Historical( - HistoricalView::new(vec![ - TraxRecord::Steps(Steps { - date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(), - count: 1500, - }), - TraxRecord::Weight(Weight { - date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(), - weight: 85. * KG, - }), - TraxRecord::Weight(Weight { - date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(), - weight: 86. * KG, - }), - TraxRecord::BikeRide(TimeDistance { - datetime: DateTimeTz( - Anchorage.with_ymd_and_hms(2019, 6, 15, 12, 0, 0).unwrap(), - ), - distance: Some(1000. * M), - duration: Some(150. * S), - comments: Some("Test Comments".to_owned()), - }), - TraxRecord::BikeRide(TimeDistance { - datetime: DateTimeTz( - Anchorage.with_ymd_and_hms(2019, 6, 15, 23, 0, 0).unwrap(), - ), - distance: Some(1000. * M), - duration: Some(150. * S), - comments: Some("Test Comments".to_owned()), - }), - ]) - .upcast(), - ), + ViewName::Historical => View::Historical(HistoricalView::new(vec![]).upcast()), } } } diff --git a/fitnesstrax/app/src/views/historical_view.rs b/fitnesstrax/app/src/views/historical_view.rs index c3d1cf0..dde7476 100644 --- a/fitnesstrax/app/src/views/historical_view.rs +++ b/fitnesstrax/app/src/views/historical_view.rs @@ -151,7 +151,7 @@ impl From> for GroupedRecords { .into_iter() .fold(HashMap::new(), |mut acc, rec| { let date = match rec.timestamp() { - Timestamp::DateTime(dtz) => dtz.0.date_naive(), + Timestamp::DateTime(dtz) => dtz.date_naive(), Timestamp::Date(date) => date, }; acc.entry(date) @@ -169,10 +169,10 @@ impl From> for GroupedRecords { #[cfg(test)] mod test { use super::GroupedRecords; - use chrono::{NaiveDate, TimeZone}; + use chrono::{FixedOffset, NaiveDate, TimeZone}; use chrono_tz::America::Anchorage; use dimensioned::si::{KG, M, S}; - use emseries::DateTimeTz; + use emseries::{Record, RecordId}; use ft_core::{Steps, TimeDistance, TraxRecord, Weight}; #[test] @@ -191,13 +191,19 @@ mod test { weight: 86. * KG, }), TraxRecord::BikeRide(TimeDistance { - datetime: DateTimeTz(Anchorage.with_ymd_and_hms(2019, 6, 15, 12, 0, 0).unwrap()), + datetime: FixedOffset::west_opt(10 * 60 * 60) + .unwrap() + .with_ymd_and_hms(2019, 6, 15, 12, 0, 0) + .unwrap(), distance: Some(1000. * M), duration: Some(150. * S), comments: Some("Test Comments".to_owned()), }), TraxRecord::BikeRide(TimeDistance { - datetime: DateTimeTz(Anchorage.with_ymd_and_hms(2019, 6, 15, 23, 0, 0).unwrap()), + datetime: FixedOffset::west_opt(10 * 60 * 60) + .unwrap() + .with_ymd_and_hms(2019, 6, 15, 23, 0, 0) + .unwrap(), distance: Some(1000. * M), duration: Some(150. * S), comments: Some("Test Comments".to_owned()), diff --git a/fitnesstrax/core/src/lib.rs b/fitnesstrax/core/src/lib.rs index d454169..4a3791c 100644 --- a/fitnesstrax/core/src/lib.rs +++ b/fitnesstrax/core/src/lib.rs @@ -1,7 +1,3 @@ -use chrono::NaiveDate; -use dimensioned::si; -use emseries::DateTimeTz; - mod legacy; mod types; pub use types::{Steps, TimeDistance, TraxRecord, Weight}; diff --git a/fitnesstrax/core/src/types.rs b/fitnesstrax/core/src/types.rs index 4de0da4..dd507fc 100644 --- a/fitnesstrax/core/src/types.rs +++ b/fitnesstrax/core/src/types.rs @@ -1,6 +1,6 @@ -use chrono::NaiveDate; +use chrono::{DateTime, FixedOffset, NaiveDate}; use dimensioned::si; -use emseries::{DateTimeTz, Recordable, Timestamp}; +use emseries::{Recordable, Timestamp}; use serde::{Deserialize, Serialize}; /// SetRep represents workouts like pushups or situps, which involve doing a "set" of a number of @@ -31,10 +31,8 @@ pub struct Steps { pub struct TimeDistance { /// The precise time (and the relevant timezone) of the workout. One of the edge cases that I /// account for is that a ride which occurred at 11pm in one timezone would then count as 1am - /// if one moved two timezones to the east. This is kind of nonsensical from a human - /// perspective, so the DateTimeTz keeps track of the precise time in UTC, but also the - /// timezone in which the event was recorded. - pub datetime: DateTimeTz, + /// if one moved two timezones to the east. + pub datetime: DateTime, /// The distance travelled. This is optional because such a workout makes sense even without /// the distance. pub distance: Option>,