Skip to content

Commit

Permalink
feat(activity): use only seconds for duration
Browse files Browse the repository at this point in the history
We don't need nanosecond precision and it would mess up the activity log due to an extra toml table

Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Feb 15, 2024
1 parent 10c90b2 commit fada53c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion crates/core/src/domain/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ enum PomodoroCycle {
Intermission,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ActivityDuration(u64);

impl From<Duration> for ActivityDuration {
fn from(duration: Duration) -> Self {
Self(duration.as_secs())
}
}

#[derive(Debug, Serialize, Deserialize, TypedBuilder, Getters, MutGetters, Clone)]
pub struct Activity {
#[builder(default = Some(ActivityId::default()), setter(strip_option))]
Expand All @@ -70,7 +79,7 @@ pub struct Activity {

#[builder(default, setter(strip_option))]
#[getset(get = "pub", get_mut = "pub")]
duration: Option<Duration>,
duration: Option<ActivityDuration>,

kind: ActivityKind,

Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/storage/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl ActivityStateManagement for TomlActivityStorage {
if activity.is_active() {
match activity.calculate_duration(date_time) {
Ok(duration) => {
activity.duration_mut().replace(duration);
activity.duration_mut().replace(duration.into());
activity.end_mut().replace(date_time);
unfinished_activities.push(activity.clone());
}
Expand Down Expand Up @@ -180,7 +180,7 @@ impl ActivityStateManagement for TomlActivityStorage {

match last_activity.calculate_duration(date_time) {
Ok(duration) => {
last_activity.duration_mut().replace(duration);
last_activity.duration_mut().replace(duration.into());
last_activity.end_mut().replace(date_time);
}
Err(_) => {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ impl EndCmd {
} else if let Some(unfinished_activities) =
activity_store.end_all_unfinished_activities(time)?
{
for activity in unfinished_activities {
unfinished_activities.iter().for_each(|activity| {
println!("Ended {activity}");
}
});
} else {
println!("No unfinished activities to end.");
}
Expand Down

0 comments on commit fada53c

Please sign in to comment.