Operating with arbitrary timezones
jdopazo at yahoo-inc.com
Fri Jul 29 19:51:47 UTC 2016
I’ve been working on Yahoo Mail and we’ve been running into multiple issues with timezones. Currently EcmaScript supports only creating Date objects with the User Agent’s timezone. However, we need to be able to operate with whatever timezone our users selected in their settings page. In most cases we just need to render dates with the correct timezone and this is currently available using the Ecma 402 APIs. However, in other cases we need to make certain computations taking into account an arbitrary timezone and this is not covered by either EcmaScript or Ecma 402.
In particular, we need to answer the following questions:
- Is a certain date in the current day/month/year? This means given a Date object, is it in the current day for an arbitrary timezone?
- When is the start of the day/month for this timezone?
Currently the only way to answer these questions is by calculating the timezone offset for the timezone around the date we’re studying. And the way to do that is to render a date using Intl.DateTimeFormat and recreate a date object: https://gist.github.com/juandopazo/b52820e368739ed19cb206e3f3893166.
Ideally, EcmaScript would allow developers to operate on a Date object for an arbitrary timezone. Would date.setTimezone(/* IANA string identifier */) work? I know it’s a problem that is in the middle between EcmaScript and Ecma 402.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss