sproutsocial / walltime-js

A JavaScript library for easily translating a UTC time to a "Wall Time" for a particular time zone.
MIT License
121 stars 12 forks source link

TimeZoneTime should implement all native Date object methods #18

Closed jacobg closed 11 years ago

jacobg commented 11 years ago

Documented here or here:

And here is one example implementation in javascript:

      TimeZoneTime.prototype.getTimezoneOffset = function () {
        return (this.utc - this.wallTime) / 60000;
      };
jgable commented 11 years ago

We already keep a reference to the offset and save currently applied to a TimeZoneTime. I can use that to implement getTimezoneOffset.

I'm hesitant to implement any of the other missing toString variants like toLocaleString because they would be hacky. We must only use UTC values on the wrapped date object to ensure no daylight savings magic and most of those existing functions operate with non UTC values; see the hacky way we implement toDateString.

jgable commented 11 years ago

It turns out that the native getTimezoneOffset includes the current daylight savings offset in the returned value. So todays offset is different than one in February (for Chicago, US anyway).

Checkout out the new unit test for this commit for more detail.

PS. Let's make the web better by not linking to w3schools.

jacobg commented 11 years ago

Awesome! Thank you!