From 85ee96f5dd30a0133147a7bc225d00214a641536 Mon Sep 17 00:00:00 2001 From: Kyle Ferguson Date: Wed, 23 Nov 2022 09:53:04 -0700 Subject: [PATCH] Updated formatting of duration to allow for more than 1 24 hour day durations. --- src/tracker.ts | 6 ++++++ test-vault/duration_accumulation_test.md | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test-vault/duration_accumulation_test.md diff --git a/src/tracker.ts b/src/tracker.ts index f60267b..7834910 100644 --- a/src/tracker.ts +++ b/src/tracker.ts @@ -204,6 +204,12 @@ function formatTimestamp(timestamp: number, settings: SimpleTimeTrackerSettings) function formatDuration(totalTime: number): string { let duration = moment.duration(totalTime); let ret = ""; + if (duration.years() > 0) + ret += duration.years() + "y "; + if (duration.months() > 0) + ret += duration.months() + "m "; + if (duration.days() > 0) + ret += duration.days() + "d "; if (duration.hours() > 0) ret += duration.hours() + "h "; if (duration.minutes() > 0) diff --git a/test-vault/duration_accumulation_test.md b/test-vault/duration_accumulation_test.md new file mode 100644 index 0000000..e774397 --- /dev/null +++ b/test-vault/duration_accumulation_test.md @@ -0,0 +1,12 @@ +# Notes +More notes for my cool project! This note shows that we can correctly display accumulated time that lasts longer than a 24 hour day! + +```simple-time-tracker +{"entries":[ +{"name":"test","startTime":1596265200,"endTime":1627887600,"subEntries":null}, +{"name":"test","startTime":1627801200,"endTime":1633158000,"subEntries":null}, +{"name":"test","startTime":1659337200,"endTime":1659423600,"subEntries":null}, +{"name":"test","startTime":1664627410,"endTime":1664631605,"subEntries":null} + +]} +```