Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATE difference should be a TIME #1135

Open
giuliolunati opened this issue Sep 30, 2021 · 6 comments
Open

DATE difference should be a TIME #1135

giuliolunati opened this issue Sep 30, 2021 · 6 comments

Comments

@giuliolunati
Copy link

d0: 1-1-2021/0:00+0:00
d1: d0 + 1:00, d1 = 1-1-2021/1:00+0:00
But d1 - d0 = 0
I would expected 1:00

@rgchris
Copy link

rgchris commented Sep 30, 2021

Subtracting dates has historically defaulted to the date-value/date only for reasons—I suspect, at least—of the more common operation: calculating the number of days between two dates. You can get your 1:00 by using difference. I don't know if that's the right way to ultimately do it, but that calculation is available:

>> difference now now - 1
== 24:00

@gchiu
Copy link

gchiu commented Sep 30, 2021 via email

@hostilefork
Copy link
Member

@gchiu: Subtracting two date values should also give a resulting date value

That doesn't make any sense. You don't subtract February from March and get January.

It's reasonable to imagine date math giving back a TIME!. Then have days months years accessors for time to help you decode the result.

>> t: 8:00 + 23:00
== 31:00

>> t.days
== 1

The tricky part is that you wind up with questions of t.hours being 7 or 31. And you have negative values... which components of a negative time are negative? All of them?

It's a messy domain. As @rgchris says, DIFFERENCE is the historical answer, and it's not a great one.

@gchiu
Copy link

gchiu commented Oct 1, 2021 via email

@hostilefork
Copy link
Member

February and March aren't dates

They are DATE! components, and once they're part of the math then you can't subtract them and get another one of them.

@rgchris
Copy link

rgchris commented Oct 1, 2021

Still less than satisfactory: date! despite the time component is intuitively, if imperfectly, a measure of days, thus I think it still appropriate that one date less another yield an integer! (unless you want to get into the uncomfortable realm of returning decimal! for e.g. now - (now - 6:00) => 0.25) which with zones could get messier still). Dates could have a, say, epoch or fixed (or something) accessor that returned the time! elapsed since an arbitrary date (sigh, let's run with Jan 1st, 1970 as a for instance) that you may get the difference in hours by stating: date1/elapsed - date2/elapsed.

Or perhaps that assumption is wrong and returning the hourly difference between two dates is correct. Then getting the count of days between two dates is a further round date1 - date2 / 24:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants