-
Notifications
You must be signed in to change notification settings - Fork 156
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
Instant.p.toString
using {timeZone: 'UTC'}
option emits +00:00
offset, not Z
as expected
#2057
Comments
This was intended at least by me; that was how I interpreted the consensus:
I'd say the important thing for round-tripping is that you serialize a Temporal object into a string and then deserialize it back into a Temporal object, and get an identical object back, which is no problem in this case. I don't think we've been concerned about deserializing an object into a string and getting the same string back (which is already broken by, for example, case insensitivity, decimal separators, and basic vs. extended format.) |
I think the difference between case insensitivity, decimals, etc. is that those changes don't affect how other Temporal APIs behave. But sZ = '2022-02-28T03:06:00Z';
s0 = Temporal.Instant.from(sZ).toString({ timeZone: sZ});
userTz = 'Europe/Paris';
Temporal.ZonedDateTime.from(`${sZ}[${userTz}]`); // OK
Temporal.ZonedDateTime.from(`${s0}[${userTz}]`); // RangeError: Offset +00:00 is invalid for 2022-02-28T03:06:00 in Europe/Paris
Temporal.PlainDate.from(sZ); // RangeError: Z designator not supported for PlainDate
Temporal.PlainDate.from(s0); // OK On the other hand, I could also see an argument that What do you think? |
I don't think appending a bracketed time zone to a string and feeding that to ZonedDateTime.from is something that we should encourage or support. We can't stop people from doing it, but it is very much not how Temporal is supposed to work, and I don't care if it breaks in some cases. I don't see it as any different from sdate = plainDate.toString();
stime = plainTime.toString();
Temporal.PlainDateTime.from(`${sdate}T${stime}`); which also works only some of the time but enough that people might do it carelessly, we also have no way to stop people from doing it, but is also very much not how Temporal is supposed to work. I see the |
In the champions meeting of 2022-05-12 we decided not to change this behaviour. |
While working on an update to the docs, I saw behavior of
Instant.p.toString
that I suspect is a behavior that we didn't intend.I expected the
UTC
timezone to result in a "Z" string in the output, just like the default behavior if notimeZone
option is provided.I don't remember discussing how to handle the
UTC
timezone in the original design of thetimeZone
option (see #741 (comment); the meeting notes don't have enough detail to know for sure) but IIRC the intent of the option was to make it easy to round-trip timestamp strings. But the current behavior makes round-tripping harder, because the simplest round-tripping code fails to roundtrip strings with a Z offset.The text was updated successfully, but these errors were encountered: