From 03f1dfcf9460ecac46f74cf0f8d8862edb390223 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 15 Sep 2017 02:46:23 +0200 Subject: [PATCH] Add a timezonechange event to Window/WorkerGlobalScope The current timezone is visible to JavaScript and changes over time. Changes may be useful to note, e.g., in a long-running calendar or mail application that may want to update dates and times without refreshing when the user resumes using the application after travel. Currently, to accomplish that, a webapp would have to poll, e.g., by repeatedly calling `Intl.DateTimeFormat().resolvedOptions().timeZone`. With this patch, an event would instead notify the application. In this patch, the event has to run to completion before the new time zone is visible to JavaScript. These semantics are taken to give users the most consistency and ensure that UIs don't get in inconsistent states with parts rendered wtih one timezone and parts with another. This choice for consistency might be a relatively large burden for implementations and may need to be revised. Some JavaScript implementations do timezone calculations for Date by using OS APIs. These OS APIs are always operating on the current timezone. To implement the semantics that the new timezone does not take effect until the event handler starts running, it would be necessary for these implementations to use an alternate library for timezone calculations. Several such libraries exist. --- source | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/source b/source index 812224dd049..d59fe76cf52 100644 --- a/source +++ b/source @@ -2894,6 +2894,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The CopyDataBlockBytes abstract operation
  • The CreateByteDataBlock abstract operation
  • The CreateDataProperty abstract operation
  • +
  • The DaylightSavingsTA abstract operation
  • +
  • The DefaultTimeZone abstract operation
  • The DetachArrayBuffer abstract operation
  • The EnqueueJob abstract operation
  • The EnumerableOwnProperties abstract operation
  • @@ -2905,12 +2907,14 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The HostPromiseRejectionTracker abstract operation
  • The HostResolveImportedModule abstract operation
  • The InitializeHostDefinedRealm abstract operation
  • +
  • The Intl.DateTimeFormat constructor
  • The IsAccessorDescriptor abstract operation
  • The IsCallable abstract operation
  • The IsConstructor abstract operation
  • The IsDataDescriptor abstract operation
  • The IsDetachedBuffer abstract operation
  • The IsSharedArrayBuffer abstract operation
  • +
  • The LocalTZA abstract operation
  • The NewObjectEnvironment abstract operation
  • The OrdinaryGetPrototypeOf abstract operation
  • @@ -15111,6 +15115,7 @@ interface HTMLStyleElement : HTMLElement {
    onbeforeunload
    onhashchange
    onlanguagechange
    +
    ontimezonechange
    onmessage
    onmessageerror
    onoffline
    @@ -88420,6 +88425,25 @@ dictionary PromiseRejectionEventInit : EventInit { +
    Time zone changes
    + +

    JavaScript programs can observe the current time zone. Date uses the time zone + through the LocalTZA and DaylightSavingsTA algorithms. + Intl.DateTimeFormat uses the time zone in its DefaultTimeZone algorithm. + Although it is not explicitly stated in the JavaScript specification, user agents may update the + current time zone over the execution of a page as the user's time zone changes, providing + different results for these algorithms over time.

    + +

    When a UA has a new time zone to present to JavaScript, as would be observable by any of + those algorithms, the user agent must first + queue a task to fire an event named timezonechange at the Window or + WorkerGlobalScope object and wait until that task begins to be executed before + actually returning a new value.

    + +

    The task source for this task is the + DOM manipulation task source.

    +

    Event loops

    @@ -89749,6 +89773,7 @@ typedef OnBeforeUnloadEventHandlerNonNull? OnBeforeUnloadEvent onbeforeunload beforeunload onhashchange hashchange onlanguagechange languagechange + ontimezonechange timezonechange onmessage message onmessageerror messageerror onoffline offline @@ -89876,6 +89901,7 @@ interface WindowEventHandlers { attribute OnBeforeUnloadEventHandler onbeforeunload; attribute EventHandler onhashchange; attribute EventHandler onlanguagechange; + attribute EventHandler ontimezonechange; attribute EventHandler onmessage; attribute EventHandler onmessageerror; attribute EventHandler onoffline; @@ -96276,6 +96302,7 @@ interface WorkerGlobalScope : EventTarget { attribute OnErrorEventHandler onerror; attribute EventHandler onlanguagechange; + attribute EventHandler ontimezonechange; attribute EventHandler onoffline; attribute EventHandler ononline; attribute EventHandler onrejectionhandled; @@ -96383,6 +96410,7 @@ interface WorkerGlobalScope : EventTarget { onerror error onlanguagechange languagechange + ontimezonechange timezonechange onoffline offline ononline online onrejectionhandled rejectionhandled @@ -115083,6 +115111,7 @@ interface External { onbeforeunload; onhashchange; onlanguagechange; + ontimezonechange; onmessage; onmessageerror; onoffline; @@ -118123,6 +118152,12 @@ interface External { languagechange event handler for Window object Event handler content attribute + + ontimezonechange + body + timezonechange event handler for Window object + Event handler content attribute + onload HTML elements @@ -118998,6 +119033,12 @@ INSERT INTERFACES HERE Global scope objects Fired at the global scope object when the user's preferred languages change + + timezonechange + Event + Global scope objects + Fired at the global scope object when the user's current timezone changes + load Event