obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

Possible to have durations displayed in selected unit?

Open Moonbase59 opened this issue 4 years ago • 6 comments
trafficstars

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?

Moonbase59 avatar Apr 24 '21 13:04 Moonbase59

I wouldn't call it "easy" but this might work for now: = ((this.end - this.start).hours * 60) + (this.end - this.start).minutes

SkepticMystic avatar Apr 24 '21 15:04 SkepticMystic

I will add a function to do this.

blacksmithgu avatar Apr 25 '21 00:04 blacksmithgu

@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 avatar Apr 26 '21 12:04 Moonbase59

@Moonbase59 for sure, dedicated functionality for this would be way better

SkepticMystic avatar Apr 26 '21 13:04 SkepticMystic

I will add a function to do this.

@blacksmithgu Is it still something you want to add? I would love to have it.

TomasLinhart avatar Feb 19 '22 03:02 TomasLinhart

@TomasLinhart @Moonbase59 I just tested it again today and it seems to be working very well now : image image It also worked perfectly without the sum operator.

icytree avatar Jun 05 '22 16:06 icytree

Can we consider this done? The Luxon objects have attributes that should cover this.

AB1908 avatar Oct 20 '22 13:10 AB1908

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.

s-blu avatar Dec 02 '22 18:12 s-blu

Haha a fun part of this is that some folks have been asking for old behavior.

AB1908 avatar Dec 03 '22 11:12 AB1908

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

s-blu avatar Dec 04 '22 15:12 s-blu