-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use Etc/Unknown
(like ICU does) to handle the case when the OS's time zone is unrecognized by ECMAScript
#25
Conversation
Etc/Unknown
(like ICu does) to handle the case when the OS's time zone is unrecognized by ECMAScriptEtc/Unknown
(like ICU does) to handle the case when the OS's time zone is unrecognized by ECMAScript
Etc/Unknown
(like ICU does) to handle the case when the OS's time zone is unrecognized by ECMAScriptEtc/Unknown
(like ICU does) to handle the case when the OS's time zone is unrecognized by ECMAScript
SpiderMonkey doesn't ever return Evaluating let dtf = new Intl.DateTimeFormat("en", {timeZoneName: "long"});
print(dtf.resolvedOptions().timeZone, ":", dtf.format()); with
|
@anba Thanks for the info, this is good to know. I'll update the OP to clarify that only Chromium has this behavior. What do you think about the proposed behavior in this PR? Do you think it'd be an improvement over the current behaviors of engines which either return "Etc/Unknown" (which cannot then be used as input) or "UTC" (which masks the problem from programmers)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support codifying this use of Etc/Unknown to match CLDR, and this looks like mostly reasonably text.
"Etc/Unknown" isn't necessarily supported by non-CLDR/ICU programs, though. For example zammad/zammad#4320 where "Etc/Unknown" (and "Europe/Kyiv") when returned from browsers caused issues. (I've only found that issue, because it's the fourth top entry when googling for Similar issues may arise for Java: shell> java.time.ZoneId.of("Etc/Unknown")
| Exception java.time.zone.ZoneRulesException: Unknown time-zone ID: Etc/Unknown
| at ZoneRulesProvider.getProvider (ZoneRulesProvider.java:281)
| at ZoneRulesProvider.getRules (ZoneRulesProvider.java:236)
| at ZoneRegion.ofId (ZoneRegion.java:121)
| at ZoneId.of (ZoneId.java:411)
| at ZoneId.of (ZoneId.java:359)
| at (#1:1) C++20's <chrono> aborts with #include <chrono>
int main() {
std::chrono::get_tzdb().locate_zone("Etc/Unknown");
} Python's zoneinfo also only supports IANA time zone names: >>> import zoneinfo
>>> zoneinfo.ZoneInfo("Etc/Unknown")
...
zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Etc/Unknown' Also found this when searching for "Etc/Unknown": Support for "Etc/Unknown" was originally added to ICU because they couldn't change their API to return |
That kind of sounds like we should accept it as input but not produce it as output. |
This is an interesting idea. My main concern would be unexpected impact of throwing on output. Would too many programs unexpectedly crash even if they weren't sending the IDs to some other system, but were just using the string for serialization between ECMAScript code? Would it degrade debugging tools, logging, Sentry, etc.? The latter is a particular concern because one of the main goals of Etc/Unknown is for it to show up in logs and debugging tools so that developers can figure out what went wrong. |
If a number of other tools will throw, shouldn't we prefer the error to happen in JS, closer to the problem, than after traveling over the wire? |
Yep, this seems like a problem with no good solutions, only bad and worse solutions. Which of below do you think would be least bad for users?
|
Yeah, it's a tough balance between keeping programs running (even if the results may be unexpected) vs. crashing and alerting developers and/or end users that something is wrong. My main concern would be crashing in a way that's difficult to reason about, because callers of Are there any other built-ins with similar throw-on- If we were to pick a place to crash that's in between "crash always" (in SystemTimeZoneIdentifier) and "crash never", then I guess another possible place to crash would be when actually using the time zone info for anything but its ID. So you could get Etc/Unknown and test the ID, but using it in any way e.g. |
To clarify, I didn't necessarily mean that toString or toJSON should throw - that was your inference. I just said we shouldn't output |
Oh, sorry for misunderstanding. Could I ask a few questions to clarify what you have in mind when the system time zone is unrecognized?
|
Certainly if the system timezone is unknown, I wouldn't be surprised by any of the Now methods either throwing, or, logging a warning to the console (which we could only suggest, not mandate) and returning something in UTC.
I think it's fine if that throws, since you're explicitly requesting a TimeZone object for which no time zone is known to exist. |
7fcd3ce
to
75ad963
Compare
I updated the text in this PR to resolve @gibson042's and @anba's review feedback. Thanks for the reviews! Also, to guide tomorrow's TG2 discussion, I added four choices of how this problem could be resolved: one that's the "OK for input and output" proposed in this PR, and three others. |
Throwing for unrecognised system time zone identifiers isn't something we should do, because it will break browsing experience for end users. And at least in the case of Firefox, it'll break the whole browser, because browser internals are also using |
b5e3aa2
to
e69f3cf
Compare
How about using Does that makes sense to you? 🤔 |
Further TG2 discussion: https://github.com/tc39/ecma402/blob/master/meetings/notes-2023-06-29.md#use-etcunknown-like-icu-does-to-handle-the-case-when-the-oss-time-zone-is-unrecognized-by-ecmascript-25 We failed to reach consensus on this issue so we'll stick with the status quo (unspecified behavior) for the time being and revisit this in the future as a standalone PR. |
Closing. Looking forward to solving this in concert with TG2 in the future. |
This PR adds explicit support for an Etc/Unknown time zone ID, which ICU returns when the system time zone is not recognized, usually because the host environment's OS uses an ID from a newer version of the IANA Time Zone Database that the ECMAScript engine has not yet been upgraded to. This time zone should behave identically to UTC, except it should have a different localized name to help programmers and end users realize that there's a problem that requires someone to resolve. See tc39/proposal-canonical-tz#25 for a previous attempt to address this issue.
This PR specifies what to do in SystemTimeZoneIdentifier (DefaultTimeZone until tc39/ecma262#3035 renames it) when ECMAScript cannot determine or doesn't recognize the OS's time zone ID. The most common cause is when new IDs are added to the IANA Time Zone Database, and the OS is updated to use this new ID, but the ECMAScript implementation has an older version of TZDB that doesn't include this ID.
Examples include renames, like
"Europe/Kiev"
=>"Europe/Kyiv"
, or brand-new Zones, like"America/Ciudad_Juarez"
that was recently added.Currently Chromium solves this problem by exposing a special ICU ID
"Etc/Unknown"
back to userland. (This ID is defined in UTS 35.) This Chromium behavior is problematic because users cannot use"Etc/Unknown"
as input. For example,Temporal.TimeZone.from(Temporal.Now.timeZoneId())
would throw.Non-Chromium implementations return
"UTC"
in this case. This behavior is also problematic because it masks the problem; programs can't detect that anything is broken because"UTC"
can mean either "this computer is set to UTC" or "this computer's time zone is unknown". This makes it impossible for programs to notify users that action is needed to resolve the issue, e.g. by upgrading the ECMAScript implementation to a later version that includes the unrecognized time zone IDs.Here are a few possible solutions. This seems like a problem with no good solutions, only bad and worse solutions. Which of below do you think would be least bad for users? Why?
"UTC"
from Intl.DTF / Temporal.Now (current non-Chromium behavior). Recommend that a warning message be logged to the console."Etc/Unknown"
from Intl.DTF / Temporal.Now, but throw if this ID is used as input to TimeZone / ZDT / Intl.DTF (current Chromium behavior)"Etc/Unknown"
from Intl.DTF / Temporal.Now and allow it as input to TimeZone / ZDT / Intl.DTF (proposed in this PR)I'd like to discuss these solutions to figure out which one may be best. To help with discussion, this PR proposes (3) above: doing what ICU does when the OS's time zone is unrecognized, which is to return
"Etc/Unknown"
as the identifier, and also to accept this ID as input.This PR makes the following spec changes:
Etc/Unknown
as input wherever time zones are accepted, e.g. theTemporal.TimeZone.from
and that type's constructor,Temporal.ZonedDateTime.from
and that type's constructor, theIntl.DateTimeFormat
constructor, etc.