-
Notifications
You must be signed in to change notification settings - Fork 2
Description
The core proposition of this proposal is that ECMAScript shouldn't change user-inputted identifiers. If the user provides Asia/Calcutta, then they should get Asia/Calcutta back. Ditto for Asia/Kolkata.
But should this rule also apply to time zone identifiers that resolve to UTC? There's 14 aliases for UTC. Most are obscure, but Etc/UTC (and perhaps Etc/GMT) will probably show up frequently, especially in inputs from other systems that follow IANA's practice of making "Etc/UTC", not "UTC" the canonical identifier for this Zone.
Here's a few reasons I'd expect users to check whether a time zone is UTC:
- Programs may want to behave differently in UTC, e.g. hide the local time in a UI because UTC doesn't represent a real place on Earth.
- Programs may check for non-UTC identifiers as a signal of whether they need to do additional processing, e.g. to check if there might have been a time zone transition.
- Programs may check for UTC identifiers as a signal that they can use a "fast path" in their code, e.g. using Instant instead of ZonedDateTime in calculations or output.
I think we have these options:
- Canonicalize, because
=== 'UTC'
is a frequently-used pattern in existing code and (unlike location-based zones) we never have to worry about it being broken in future TZDB releases. - Don't canonicalize. This makes UTC-resolving IDs consistent with all others, so that users don't get in the habit of using
===
to compare any IDs, including UTC. - Don't canonicalize, but recognize UTC's special role by creating another TimeZone method like
TimeZone.p.isUTC
to check to see whether an identifier or time zone object is UTC. It'stz.isUTC()
would be shorthand fortz.equals('UTC')
, which doesn't save much ergonomically, but would be much more discoverable in IDE auto-complete and in docs.
My current preference is for option (2) because it's simplest and most consistent, and then we can always add (3) later if too many users are still getting tripped up by using === 'UTC'
.
But I wanted to get others' feedback too.
Here's the identifiers that resolve to 'UTC'
in ECMAScript:
Etc/GMT+0
Etc/GMT-0
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/Universal
Etc/Zulu
GMT+0
GMT-0
GMT0
Greenwich
UCT
UTC
Universal
Zulu