Skip to content

Instantly share code, notes, and snippets.

@littledan
Last active July 9, 2020 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save littledan/96194e71ab7760dde1843dbe7611537d to your computer and use it in GitHub Desktop.
Save littledan/96194e71ab7760dde1843dbe7611537d to your computer and use it in GitHub Desktop.
ontimezonechange explainer

The current timezone is visible to JavaScript in a few ways, such as:

Intl.DateTimeFormat().resolvedOptions().timeZone
new Date().toString()

The current timezone can change, for example in mobile when the user physically moves to a new location and on desktop when the user changes their system timezone settings. These changes do not require a page reload, but rather are observable within a single page running JavaScript, relatively consistently across browsers, although there are no web-platform-tests for this behavior.

Web apps with timezone-specific UI, such as calendar apps, email applications, or event schedules, may want to respond to timezone changes to update dates and times accordingly. Currently, web apps have no way to accomplish this without repeatedly polling for the current timezone. This proposal introduces a new timezonechange event that instead notifies the application.

The event is made available to Window and Worker contexts alike.

Illustrative example:

renderWithCurrentTimezone();

globalThis.addEventListener('timezonechange', event => {
  renderWithCurrentTimezone();
});

(Note: This explainer was coauthored with Mathias Bynens.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment