andrew at ishiboo.com
Wed Feb 20 06:24:07 PST 2013
The approach I've taken is to implement a native DateTz type which
internally stores the UTC Date as well as the Date in the offset specified
by either the user or an IANA timezone string. The non-UTC ES Date API then
returns the local datetime in the specified timezone. The API is kept to a
minimum to avoid adding much on top of the ES Date:
var a = new DateTz(Date.now(), -300);
var b = DateTz.inTz(Date.now(), "Asia/Tokyo");
The returned objects simply proxy the public API of ES Date to the internal
Date objects, so the above are the only real additions to the API surface.
On Wed, Feb 20, 2013 at 12:52 AM, Jonathan Adams <pointlessjon at me.com>wrote:
> I understand that an implementation of ECMAScript is expected to determine
> the local time zone adjustment .
> This is really convenient -- most of the time. However, it would be great
> to override this for a given Date object. It doesn't appear that we can at
> the moment  or in ES6.
> If we could override this context, we can then take advantage of some of
> the other native methods such as Date.toString(), Date.getDate() etc. using
> our preferred, altered LocalTZA rather than users having to build horrible
> user-land functions  and wrestle with daylight savings time adjustments
> My particular use-case involves taking dates generated in CST, stored as
> UTC (this is good) but then I want to offer a list of dates relative to
> CST, but this is processed in a context with LocalTZA for PST. I can get
> away with faking it by calculating the difference in timezones and altering
> the timestamp used to generate a new Date object but, this is going to
> technically be off at some points in time (DST adjustment for example) and
> feels wrong/hacky.
>  http://people.mozilla.org/~jorendorff/es6-draft.html#sec-18.104.22.168
>  https://mail.mozilla.org/pipermail/es-discuss/2011-March/013322.html
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss