-
Notifications
You must be signed in to change notification settings - Fork 152
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
Interaction of Duration vs DST (or other TZ offset changes) #559
Comments
@justingrant while |
@ryzokuken Honestly I'm not familiar enough with balancing use-cases to have an opinion. I know that the classic JS |
@justingrant keep in mind that you don't have to balance either. |
(of course you could balance and then use something like |
Whether to balance 24 hours ↔ 1 day is something we've gone back and forth on a few times, so I think that's open to discussion if need be. |
While researching #558, I learned how Java handles the problem of DST and durations. Java has a time-only duration type |
@ryzokuken - following up on your question from a few weeks ago:
I agree. Now that I understand the Temporal API better, my answer is "yes, we should stop balancing 24 hours into days" from
It's an interesting question whether BTW, I have more research and suggestions to share about how |
While researching #558, I learned more about how iCalendar handles durations and DST:
The DST behavior is interesting. According to this doc, RFC 5545 has a concept of "nominal durations" (in local clock time, like
BTW, this "duration times are absolute, duration dates are not" convention matches how moment.js has been handling date-time math since 2011. Temporal use-cases are broader than iCalendar's, so this "absolute time/calendar date" convention may not cover all Temporal use cases. But it's also a common use case, so as we investigate improvements in the Duration API, we should make sure that any improvements work for this case too. |
When dealing with Absolutes, 1 day == 24 hours, which is consistent with the expectations shared by the champions. When dealing with Dates and DateTimes, 1 day == 1 calendar day. A Duration is merely a bag of options that is interpreted in the context of the concrete Temporal type you give it to. |
Yep, that's the core problem. Unlike all other Temporal types, if you have a function that accepts a This inherent ambiguity is unexpectedly different from the rest of Temporal which avoids ambiguity by using strong typing and separation of concerns to help developers avoid mistakes. By analogy, Temporal could have offered a single date/time type instead of a Why is |
I see Duration as a helper class on the side. The absolute/clock distinction is done in the primary Temporal types. All that being said, if we add ZonedAbsolute, then we could define Duration days the same way as RFC 5545. We just wouldn't support days in Absolute arithmetic, only ZonedAbsolute.
|
Yep, this is probably the core of where we're not aligned re: durations. I suspect the disconnect is related to use cases. The "three kinds" ambiguities only matter when doing math operations. Some use cases like parsing and formatting don't generally need math, so for those use cases But for use cases that make heavy use of
This seems like a good option to consider as an alternative to other solutions like a What impact would "define Duration days the same way as RFC 5545" have on DateTime's |
FYI, I wrote up a bunch of options in #686 for how Temporal could address the problems discussed here in this issue related to the ambiguous meaning of the current It's a long writeup so I figured it made sense to move into a new issue, but also happy to merge it back into this one if that'd be better. |
We've moved pretty far past the discussions in this issue. In particular, LocalDateTime will land soon which is the recommended way to do DST-safe math. Developers who want to work with other kinds of durations can use Absolute or DateTime math. So closing this issue. |
I'm reviewing the latest proposal and couldn't find discussion of how
Duration
is affected by DST, if at all. Is there docs or GH issue discussion on this? The particular line in the docs that concerned me was this one:This is also a problem for days, which can have 23, 24, or 25 hours... or in theory even 23.75 or 24.5 in oddball cases like when countries change their timezone offsets, per Wikipedia:
It's a valid decision for Duration to ignore DST and to treat all "duration days" as exactly 24 hours, but I think this decision should be much more explicit in the docs, e.g. DST notes in every method's docs for the Duration API.
The
plus
andminus
methods of Duration seem particularly vulnerable to this misunderstanding, because P24H may not yield equivalent results (e.g. when adding or subtracting from a DateTime) as P1D in a DST timezone, and it's easy to introduce this bug by using these methods.The text was updated successfully, but these errors were encountered: