Tracking time in daily notes using ISO 8601 duration fields

I’ve been experiment with ways to track and summarize time in daily notes, particularly with the bases feature, and I finally found something that seems to work well.

Tracking

In each daily note, I’m adding a string field for the total duration for that day in ISO 8601 format. An example is “PT1H45M” (for 1 hour and 45 minutes). Here’s a handy cheat sheet ISO 8601 Cheat Sheet.

Summarizing in Bases

To summarize, I have a base with all of the daily notes for a year (grouped by month for convenience). For fields that I want to track, I added a Custom Summary. The formula is values.filter(duration(value)).map(duration(value)).reduce(value+acc,duration(“PT0M”)).hours . I had to piece this together from help and other posts, so I’ll break it down.

  • values.filter(duration(value)): only use values that have a valid duration
  • map(duration(value)): turn each value into a duration
  • reduce(value+acc,duration(“PT0M”)): add all the durations
  • hours: show the total number of hours

I’m not sure if it’s the most efficient formula, but it does work. Hope this helps someone.

2 Likes

Does the duration function actually parse ISO 8601 formatted duration strings? I can’t get it to parse, for example, “PY5” as five years. It’ll happily parse “5y”, “5 years” and “5 y” though.