obsidian-dataview
obsidian-dataview copied to clipboard
Possible to have durations displayed in selected unit?
Sometimes one wishes to add up durations, or simply display them in a specified unit, like minutes or hours.
Let’s take this example:
---
start: 2021-04-24T14:00
end: 2021-04-24T15:30
---
### Test duration
`= this.end - this.start`
`= (this.end - this.start).minutes`
It will display:
1 hours, 30 minutes
30
So if I specify .minutes it’ll only display the minutes part of the duration (30), not it’s actual length in minutes (90).
Any easy way to do this?
I wouldn't call it "easy" but this might work for now: = ((this.end - this.start).hours * 60) + (this.end - this.start).minutes
I will add a function to do this.
@SkepticMystic This wouldn’t work in all situations, just think of DST switching … and it wouldn’t just be hours, but weeks, months and years, too, you’d have to add.
Best bet might be to use moment.js internally, I think.
@Moonbase59 for sure, dedicated functionality for this would be way better
I will add a function to do this.
@blacksmithgu Is it still something you want to add? I would love to have it.
@TomasLinhart @Moonbase59 I just tested it again today and it seems to be working very well now :
It also worked perfectly without the sum operator.
Can we consider this done? The Luxon objects have attributes that should cover this.
This works now as intended.
I'll close the issue as resolved. If you still see any problem here, please comment on the issue with details on what is not working as expected and I'll reopen your report.
Haha a fun part of this is that some folks have been asking for old behavior.
Haha a fun part of this is that some folks have been asking for old behavior.
That's still possible with some math.
= (this.end - this.start).minutes % 60 = 30