Skip to content

Should identifiers that resolve to UTC always be canonicalized? #21

@justingrant

Description

@justingrant

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:

  1. 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.
  2. 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.
  3. 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:

  1. 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.
  2. 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.
  3. 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's tz.isUTC() would be shorthand for tz.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         

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions