-
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
Should time zone offsets be signed Durations? #935
Comments
Interesting idea. Seems like a nice usability win if we can make it work. The main concern I'd have for this would be ambiguity in the string format between If do end up parsing
Note that I'm not arguing that we should parse offsets into Duration outside the context of TimeZone and LDT. I don't have an opinion about that question. But I am pointing out some questions to address if we did it. Also, what about What about If we made this change, then we'd probably want to rename the property to |
Also, I just remembered why I specified this property as a |
I'm not opposed to changing offset-nanoseconds to offset-duration throughout, and s/offsetNanoseconds/offset/. We had a similar discussion in #349 but at the time durations were not signed. If we do this, I do feel strongly that we should not add |
|
Here's consensus I heard at 2020-10-02 meeting. (1)-(5) are straightforward. (6) requires decisions. Make the following changes to the ZonedDateTime type:
BTW, I realized after the meeting that the unappetizing options in (6) was the main reason why I originally opted to use the nanoseconds property instead of a string.
|
I would vote for 6.3, and hopefully the result can round-trip with |
Could you please remind me why this was deemed necessary? Regarding the options, I'd personally prefer 6.1 because we've failed to come up with (IIRC) use-cases for sub-minute offsets. 6.4 is less preferable, because it's essentially the same, but passive-aggressive, which breaks the "err sooner rather than later" principle. 6.2 is fine, as long as we move ahead with the format on the standards track similar to the calendars discussion. |
Maybe I've missed something here, but does that mean there's no longer a way to get the offset as a numeric value? If so, that's a complete reversal of several previous discussions. #349 and #579 both questioned why the offset was previously only returned as a string instead of a numeric value. (I'm using "numeric value" to cover both nanoseconds and Durations.) When I first looked over the cookbook examples I also questioned this — #240 (comment)
I also saw in the meeting notes about this decision that "It's not like you're doing maths with the offset." (Of course, if I have missed something, and a numeric value is still easy to obtain, then feel free to ignore everything above. 😄) |
Oh also...
That will cause problems with existing IANA zones. See #339 (comment) |
You can still get the numeric value from the TimeZone object, with |
Hrm, so to mimic an existing usage of the legacy Instead of getting the numeric offset directly, I have to get the time zone object, then ask it for the numeric offset of an instant that I also have to get from the original object. // Before
someZonedDateTime.timeZoneOffsetNanoseconds
// After
someZonedDateTime.timeZone.getOffsetNanosecondsFor(someZonedDateTime.instant) That will work for my use cases. But frankly, I don't see how this helps resolve feedback about the API being too verbose. |
(Bundling up responses to multiple folks.)
Good points. I'd forgotten about historical timezones with sub-minute offsets. This seems like a good reason to support round-tripping ZDT instances via strings that use the actual offsets. Otherwise you can end up with weird results, e.g. times that should be equal will return
After thinking about this problem more, I think 6.2 this is the best option: if there's a sub-minute offset (which currently is only for historical values), then we should emit it in
I agree. Having the offset as a numeric value is helpful. Regardless of what we decide with this issue, it seems helpful to retain the numeric convenience property on ZonedDateTime, e.g. Another thing that occurred to me: parsing offset strings is relatively common. Should there be static convenience methods on TimeZone for this purpose, e.g.
Good point. Regardless of which property is a field it seems sensible to keep both properties and to make the property names shorter, e.g.
IMHO the main round-trip issue is string serialization, which is not helped by the
IMHO, it would be weird if |
Remember that this is a concern about nanoseconds being overly cumbersome for the overwhelming majority of offsets that are in fact aligned on 15-minute boundaries (and all but a handful of those actually on hour boundaries). I proposed Duration as a means of simplifying common cases without precluding the uncommon ones (e.g., |
Sounds like more discussion may be needed to finalize the decisions in this issue. I added it back to the design milestone. BTW, in the meantime I updated the ZDT prototype and proposal in #700, as well as the ZDT docs in #979, to shrink the property names to |
Can we see if we can resolve this online without waiting until the next meeting? Would a combination of Richard's and my comments have broader support? Namely:
|
Yep, I'd like to resolve online too! I dug into the options of (6) and I think it's actually more complicated than the 4 original options in #935 (comment). So here's an updated set of decisions to make. Some combinations of choices aren't valid, but some of these decisions are mutually exclusive. LMK if I missed any decisions or options and we can iterate. 1. How should Temporal behave when executing a TimeZone method for an Instant that has a sub-minute offset in that time zone?
2. How should ZonedDateTime's and Instant's
3. How should
4. How should
5. How should
6. How should
7. How should
8. How should ZonedDateTime's string
9. How should ZonedDateTime's
There's no perfect choice here. My current medium-strength preference would be to pick the (a) options for all of them, meaning:
My second choice is probably (2a) which is to force all TimeZone instances (built-in and custom) to only use minute-aligned offsets. This would presumably foreclose the ability to have a TAI timezone or other leap-second solutions via custom timezones. Currently, my only strong opinion would be to be NOT choose (2b) because it'd prevent us from matching a future standard where sub-minute offsets are allowed. Let's discuss. |
Having mulled things over more, I think the deviation from ISO 8601 to include increased offset precision in the obvious way (and pushing for standardization thereof) makes the most sense. |
Cool. If I understand your proposal correctly, I have a concern:
I see a lot of value in limiting If the option is expected to change behavior if a new standard is approved (which it'd probably be if its name were But I'm not sure that this option is needed on entry into Temporal given how rare it is and given that any app concerned about interop will already be restricting the output via Also, there's a trivial userland workaround for developers who really care about this: if (ZonedDateTime.from(s).offsetNanoseconds % 6e10) throw new RangeError('invalid offset'); Also, we could wait to see if lack of a parsing option generates lots of complaints, and if it does then such an option could always be added later. Finally, there will always be "stickler" developers who will see that there's an option for standards compliance and will mandate it for their codebases. This would make it harder for them to transition if a new standard is approved. |
OK, I find that argument convincing. |
Meeting 2020-10-15:
|
* Shorten `offsetString` property to just `offset` * Remove `offsetNanoseconds` from ZDT fields. Replace it with `offset`. * NOTE: subminute offsets aren't supported yet, but will be later (tc39#935)
* Shorten `offsetString` property to just `offset` * Remove `offsetNanoseconds` from ZDT fields. Replace it with `offset`. * NOTE: subminute offsets aren't supported yet, but will be later (tc39#935)
For avoidance of doubt: the historical mean time of Amsterdam is indeed UTC+00:19:32.13, but the tzdata database only supports whole-second offsets, so it is rounded to UTC+00:19:32. I don't think anything needs to change about the resolution of this issue. |
* Shorten `offsetString` property to just `offset` * Remove `offsetNanoseconds` from ZDT fields. Replace it with `offset`. * NOTE: subminute offsets aren't supported yet, but will be later (tc39#935)
This is necessary for round-tripping of some named time zones. In particular we are testing with Europe/Amsterdam before 1937. See: #935
Allows time zone offsets such as +00:19:32.13 in Temporal.Instant.from, Temporal.TimeZone.from, and new Temporal.TimeZone. See: #935
This is necessary for round-tripping of some named time zones. In particular we are testing with Europe/Amsterdam before 1937. See: #935
Allows time zone offsets such as +00:19:32.13 in Temporal.Instant.from, Temporal.TimeZone.from, and new Temporal.TimeZone. See: #935
getOffsetNanosecondsFor
andtimeZoneOffsetNanoseconds
seem tremendously cumbersome for the overwhelming majority of time zone offsets that have zero values for seconds and fractional seconds. Rather than propagating huge integers, perhaps we should be dogfooding Temporal.Duration instances and letting any author who actually wants nanoseconds to useround
.The text was updated successfully, but these errors were encountered: