A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

Add Event for changing current timezone?

littledan
2017-03-20

JavaScript includes several pieces of functionality which are based on the current timezone. For example, new Date().getHours() will get the hour of the day in the current timezone, and Intl.DateTimeFormat().resolvedOptions().timeZone will get the IANA timezone descriptor. Multiple browsers keep track of changes in the current timezone within a single page load, so if you have a long-running page and go to a different place, the timezone is adjusted without a reload (modulo bugs).

This is useful for any long-running web site which renders dates. For example, imagine having your mail or calendar open on your phone, putting it in airplane mode, going somewhere, and then resuming use with network after landing. It’s nice to have everything updated appropriately.

Currently, the only API for finding out about this timezone change is to poll one of these information sources. Polling is a little suboptimal–what if we made an event for it? This would be something that fires on window, with no data in the event (since there’s already an API to read the timezone). In IDL, I guess that would be

partial interface WindowEventHandlers {
   attribute EventHandler ontimezonechange;
}

Any thoughts/opinions? cc @domenic

mounir
2017-03-25

Couple of relevant discussions:

McMurphy
2017-05-08

IMHO You are really asking for background GeoLocation with timezone merely a derivative.

That is, for a given Lat/Lng on a given date you’re in timezone X. If it’s different to what it was last time then trigger the timeZoneChange event.

Either way you’ll need background processing which seems anathema to those creating specs.

“Background GeoLocation” the font from all goodness flows!