mde / timezone-js

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

Timezones without a / not accepted by Date() constructor #95

Closed TrevorBurnham closed 11 years ago

TrevorBurnham commented 11 years ago

Because TZ_REGEXP requires a / to match, a call like

new timezoneJS.Date(+new Date(), 'Iceland')

does not interpret the second argument as a timezone, even if the backward zone file has been loaded.

longlho commented 11 years ago

hmm this gets tricky since a string parameter can be both with a time string and a timezone string. That's why we use the '/'.

TrevorBurnham commented 11 years ago

How about interpreting the string as a timezone if Date.parse(str) returns NaN? There are a few valid timezones that some browsers will generously interpret as dates (specifically, those of the form GMT+n or Etc/GMT+n), but those aren't actually valid dates in ISO 8601, so it's OK to strip them.

So instead of

TZ_REGEXP.test(args[args.length - 1])

I'm suggesting

isNaN(Date.parse(args[args.length - 1].replace(/GMT\+\d+/, '')))
longlho commented 11 years ago

Hmm yeah that should work. Care to pull request? :)