mde / timezone-js

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

Bug: Units must be a number #133

Closed alessioalex closed 4 years ago

alessioalex commented 10 years ago

How to replicate:

new timezoneJS.Date(2014, 2, 11, 13, 0, 'Europe/Samara').toISOString()

Note: this can be usually replicated when using timezones with >= +03:00 GMT

alessioalex commented 10 years ago

So far it has come down to the following line (in the setTimezone function):

this.setUTCMinutes(this.getUTCMinutes() - this.getTimezoneInfo().tzOffset + previousOffset);

When I console logged the info it seems previousOffset is a String instead of a Number, so if you do 0 + '-240' it will equal '0-240'.

I'm not sure why it's a String and not a Number, but a quick fix is to turn previousOffset into a Number, like so:

this.setUTCMinutes(this.getUTCMinutes() - this.getTimezoneInfo().tzOffset + Number(previousOffset));
mde commented 10 years ago

Could you put this in a PR, with the relevant test?

alessioalex commented 10 years ago

@mde certainly. I would like to digg in more into the cause, so it will take me a couple of days before I submit it.

ewjoachim commented 10 years ago

If it can help, I've had the same problem for dates in zone Europe/Paris before 25/12/1979 or something.

sdemjanenko commented 9 years ago

I just ran into this when loading the pre-parsed Olson data.