mde / timezone-js

DEPRECATED: Timezone-enabled JavaScript Date object. Uses Olson zoneinfo files for timezone data.
824 stars 182 forks source link

Creating new timezoneJS.Date object using timestamp or existing Date object #19

Closed itsuryev closed 12 years ago

itsuryev commented 12 years ago

In the README it states:

Create a timezoneJS.Date the same way as a normal JavaScript Date, but append a timezone parameter on the end

In JavaScript we can do following:

var date1 = new Date();
var date2 = new Date(date1.getTime());
var date3 = new Date(date2);

This will create new Date objects. Both cases doesn't seem to work with timezoneJS.Date object. We have to do

var date = new Date();
var dt = new timezoneJS.Date(date.getFullYear(), date.getMonth(), ..., 'Asia/Tokyo');

This may be not an actual issue if it was not planned to support such use case but please consider it as useful feature request then.

longlho commented 12 years ago

good idea I'll look into this

longlho commented 12 years ago

timezoneJS.Date should support this already. I've added 2 unit tests in date.spec.js if you wanna take a look and see it that's what you're looking for.

itsuryev commented 12 years ago

Please note that there is difference between var dt = new timezoneJS.Date(0); and var dt = new timezoneJS.Date(0, 'America/Los_Angeles'); The later one doesn't work (applies to passing timestamp and Date object).

longlho commented 12 years ago

yup that is correct. The whole business of trying to figure out 7 possible constructors is kinda fuzzy. I'll definitely take a look at this.

For now a workaround is that you can setTimezone after initializing timezoneJS.Date object.

mde commented 12 years ago

Thanks for adding the tests on this. Awesome work.

longlho commented 12 years ago

I've put in the support for the cases you mentioned. Still working on the case timezoneJS.Date(timeString, tz) since both are strings it gets tricky.

longlho commented 12 years ago

Allow String constructor also in commit e711f49