-
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 Absolute.prototype.toString(timeZone)
have options to omit the offset or time zone?
#741
Comments
Supporting non-ISO datetime strings (with bracketed time zone) for parsing discussed in #716 is one thing. To me the only advantage is to support interop. But outputting such strings, I'm really against. Worse to be able to omit the offset but keep the time zone? Are we inventing yet another new extension to ISO here? ISO in any case should be the default for output. As mentioned in #716, sending a non-conform ISO string will make my server code crash for example. Having to add an option every time to stick to the ISO standard ( |
To clarify, the time zone suffix is only added when the Temporal.now.absolute().toString()
// => "2020-07-09T03:23:19.986994478Z"
Temporal.now.absolute().toString('-0700')
// => "2020-07-08T20:23:14.478676279-07:00"
Temporal.now.absolute().toString('America/Los_Angeles')
// => "2020-07-08T20:24:52.496999986-07:00[America/Los_Angeles]" This issue is about adding optional behavior when an IANA time zone is supplied to |
Dumping an ISO string for an absolute and a time zone is not trivial?
|
Some feedback related to the default for the time zone display option: @niklasR said at #703 (comment):
@thojanssens said in #703 (comment):
If we adopt the proposal in this issue, then it makes sense to keep this feedback in mind when we choose defaults. Also, if |
That will be unintuitive. I call toString with a given time zone and I get an iso string without time zone. I call toString on an object containing a time zone but now the time zone is included in the string. In both cases the time zone is provided, but the toString output is different. I understand it's called from a different object, but as soon as you give the time zone to absolute, you have the same information, why should the output be different:/ |
After participating in the discussion in our weekly meeting about this, someone mentioned that serializing an Absolute with a time zone will no longer be necessary if we have (the type currently known as) LocalDateTime, because instead you would convert to LocalDateTime. My preference would be to remove the time zone argument from I don't think I'd be in favour of an option to leave the IANA name out of the toString of LocalDateTime, and rather put the burden of that problem on the parsing side (#716). But maybe for the use case of someone who absolutely cannot have brackets past the end of their ISO string, we should have a separate toISOString method in LocalDateTime, or some ergonomic way, given an IANA time zone, to get the corresponding offset time zone for a particular Absolute, or both. (e.g. |
Agreed.
Agreed. Using the current LDT design, you'd do this: `${ldt.toDateTime()}${ldt.timeZoneOffsetString}` I'm not sure any further ergonomicity (is that a word?) is required. Especially not if #742 is resolved in a way that we can have a `${ldt.dateTime}${ldt.timeZoneOffsetString}` If we do offer a convenience method for this format, it should probably be on Absolute (or TimeZone), not LocalDateTime, because once you strip off the IANA identifier then you no longer have a LocalDateTime; that string wouldn't be valid for parsing back into Also, I probably wouldn't call it |
I prefer @ptomato 's argument that Absolute should stick to UTC output, if we have a zoned datetime. Makes sense.
One could ask why don't we have a I'd rather see a
That rejoins my point about working with non iso strings. But if we suppose then that Temporal works with the extended format by default, in the end, the output for an absolute is also in the extended format, it's just that it doesn't have a time zone (well, utc). In other words: all toString methods for any object return the format defined for Temporal. It just happens that the output of e.g. absolute is ISO compatible. Then we have an extra method in the zoned datetime for enforcing ISO. Makes all sense to me. |
In today's meeting, we tentatively decided to remove the |
Instead of choosing a time zone in which to serialize an Absolute, the recommended way to keep a time stamp with a time zone is LocalDateTime (either serialized or not.) Closes: #741
I have this in a branch at https://github.com/tc39/proposal-temporal/tree/716-741-absolute-zone-names but it should not be merged until LocalDateTime lands. |
Instead of choosing a time zone in which to serialize an Absolute, the recommended way to keep a time stamp with a time zone is LocalDateTime (either serialized or not.) Closes: #741
The new proposal (#703 (comment)) is to keep the time zone argument in Absolute.toString but only print the offset. |
(That seems fine to me.) |
Instead of choosing a time zone in which to serialize an Absolute, the recommended way to keep a time stamp with a time zone is LocalDateTime (either serialized or not.) Closes: #741
A counter proposal from today's meeting was that the time zone argument should be dropped, since we are getting a way to emit a string with an offset and no bracket in LocalDateTime.toString already. After considering it, I personally am convinced to stick to Justin and Philipp's last proposal, to keep the time zone argument but only print the offset. The reason being that Absolute.from accepts a date/time/offset combination, Absolute.toString should also emit it. |
Agreed. The basic idea is that Absolute has two valid canonical formats: one that ends in Z and another that ends in an offset. "Z" is the default, but if you're interoperating with another system that uses the other format, then you should be able to round-trip that format in both parsing and toString. |
2020-09-04 meeting decision:
|
I think it's very unidiomatic to have "absent" and |
Oops, agreed. I edited the comment to the specify the idiomatic behavior. |
I've taken the liberty of renaming this, otherwise it has a conflicting meaning compared with the 'timeZone' option passed to Instant.toString() (which will be added in #741.) Making the distinction between 'timeZone' and 'timeZoneName' in this way aligns exactly with what Intl.DateTimeFormat does. See: #703
I've taken the liberty of renaming this, otherwise it has a conflicting meaning compared with the 'timeZone' option passed to Instant.toString() (which will be added in #741.) Making the distinction between 'timeZone' and 'timeZoneName' in this way aligns exactly with what Intl.DateTimeFormat does. See: #703
I've taken the liberty of renaming this, otherwise it has a conflicting meaning compared with the 'timeZone' option passed to Instant.toString() (which will be added in #741.) Making the distinction between 'timeZone' and 'timeZoneName' in this way aligns exactly with what Intl.DateTimeFormat does. See: #703
I've taken the liberty of renaming this, otherwise it has a conflicting meaning compared with the 'timeZone' option passed to Instant.toString() (which will be added in #741.) Making the distinction between 'timeZone' and 'timeZoneName' in this way aligns exactly with what Intl.DateTimeFormat does. See: #703
This adds an option for the time zone in which to print an Instant, instead of having it be a separate argument. Also removes printing the bracketed name from Instant. Closes: #741
This adds an option for the time zone in which to print an Instant, instead of having it be a separate argument. Also removes printing the bracketed name from Instant. Closes: #741
This adds an option for the time zone in which to print an Instant, instead of having it be a separate argument. Also removes printing the bracketed name from Instant. Closes: #741
I missed these in #741 because of the CI job failing.
I missed these in #741 because of the CI job failing.
From: #716 (comment):
Currently
Absolute.prototype.toString(timeZone)
always emits both offset and IANA time zone identifier. But the feedback above raises a good point: some apps might know ahead of time that they want to store the time zone but not the offset, or the offset but not the time zone. It seems reasonable for Temporal to support those use cases.Should
Absolute.prototype.toString(timeZone)
provide an option to prevent emitting of either the offset or the IANA time zone identifier? This would allow app devs to plan ahead and avoid any possible parse-time conflicts without requiring the additional complexity of managing two separate strings.Here's an idea for syntax:
The same options object could be used by
LocalDateTime.prototype.toString
.This issue is related to #716 (which is also about handling offset vs. timezone conflicts) but this issue deals with preventing the same conflict during persistence instead of during parsing like #716. Unfortunately, I don't think that one of them removes the need for other because persisted strings may be produced by or digested by non-Temporal code.
Note that omitting the offset would make persistence non-round-trippable because the same
DateTime
+TimeZone
pair can correspond to two differentAbsolute
values, e.g. after backwards DST transitions.The text was updated successfully, but these errors were encountered: