Skip to content

Commit

Permalink
Updated formatting of duration to allow for more than 1 24 hour day d…
Browse files Browse the repository at this point in the history
…urations.
  • Loading branch information
Kyle Ferguson committed Nov 23, 2022
1 parent 402b97c commit 85ee96f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test-vault/duration_accumulation_test.md
Original file line number Diff line number Diff line change
@@ -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}
]}
```

0 comments on commit 85ee96f

Please sign in to comment.