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

Durations always show "1 month" for 28/30/31 day differences

Open AngelCherub opened this issue 4 years ago • 8 comments

What happened?

The table below is using a duration query to work out the amount of time elapsed since a specific start date: 2021-10-19

When parsed, the query says 15 November is 3 weeks and 6 days since the start date.

It then says that 16 November is 1 month since the start date.

It then says that 17 November is 1 month and 1 day since the start date.

It then says that 18 November is 1 month since the start date.

It then says that 19 November is also 1 month since the start date.

It then says that 20 November is 1 month and 1 day since the start date.

a52ee6627bba0d9982bac7587650145f043b7644

Am I doing something wrong or is this a bug?

Thanks

Angel

DQL

**Date** | **Duration**
:------------ | :------------
2021-11-15 | `=date(2021-11-15) - date(2021-10-19)`
2021-11-16 | `=date(2021-11-16) - date(2021-10-19)`
2021-11-17 | `=date(2021-11-17) - date(2021-10-19)`
2021-11-18 | `=date(2021-11-18) - date(2021-10-19)`
2021-11-19 | `=date(2021-11-19) - date(2021-10-19)`
2021-11-20 | `=date(2021-11-20) - date(2021-10-19)`

JS

No response

Dataview Version

0.4.21

Obsidian Version

0.12.19

OS

MacOS

AngelCherub avatar Dec 08 '21 21:12 AngelCherub

I add this question: as dateformat() to define the date format output, there's any kind of durationformat() to define duration format?

mnvwvnm avatar Dec 08 '21 23:12 mnvwvnm

That looks like a bug, and a very odd one at that. Perhaps I'm doing date-date subtraction or rendering incorrectly?

blacksmithgu avatar Dec 10 '21 23:12 blacksmithgu

Wish I had the brains to answer that question, but I don't. Thanks for looking at the issue.

Angel

AngelCherub avatar Dec 16 '21 18:12 AngelCherub

I dug into this more and it turns out this is kind of complicated, but it's because Luxon considers '28 days', '30 days' and '31 days' to all be '1 month'; it also takes daylight savings time into consideration as well, which is a little annoying.

This seems like a very tricky fix; I underestimated how difficult durations are to work with! I'll have to think on this a little more on how to make it ergonomic.

blacksmithgu avatar Jan 21 '22 21:01 blacksmithgu

Understand the explanation. Gulp. Very tricky. Thanks for looking into it.

Angel

AngelCherub avatar Jan 22 '22 13:01 AngelCherub

I noticed today that a simple count of just days in isolation (no years, months, or weeks) leads to a miscalculation in DV. DVJS appears to get it right. Don't know if this is related or helpful, but ...

https://forum.obsidian.md/t/how-to-calculate-duration-between-dates-in-dataview/31225/14

Angel

AngelCherub avatar Feb 10 '22 11:02 AngelCherub

Any traction on this? There are workarounds but it would greatly simplify duration queries if it could be fixed

GovSat1 avatar Jul 09 '23 15:07 GovSat1

I found this date diff bug today and found a temp workaround here (thanks @GovSat1): https://github.com/blacksmithgu/obsidian-dataview/issues/1966

But add my vote to getting this bug fixed.

bharker75 avatar Jan 19 '24 23:01 bharker75