mde / timezone-js

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

Creating Date objects with abbreviated timezone names not working #49

Closed stuartf closed 11 years ago

stuartf commented 11 years ago

The tests make it look like I should be able to create the date object in either of the following ways:

--(stuart@battra:pts/4)------------------(/home/stuart/src/hilary)(win-compat)--
--(1132:Wed,07 Nov 12:$)-- node
> var tz = require('timezone-js');
undefined
> var fs = require('fs');
undefined
> tz.timezone.zoneFileBasePath = '/home/stuart/src/hilary/node_modules/oae-util/tz';
'/home/stuart/src/hilary/node_modules/oae-util/tz'
> tz.timezone.transport = function(opts) {
...     if (opts.async) {
.....         if (typeof opts.success !== 'function') return;
.....         opts.error = opts.error || console.error;
.....         return fs.readFile(opts.url, 'utf8', function (err, data) {
.......             return err ? opts.error(err) : opts.success(data);
.......         });
.....     }
...     return fs.readFileSync(opts.url, 'utf8');
... };
[Function]
> tz.timezone.init();
undefined
> var date = new tz.Date(null, 'UTC');
undefined
> date
{ _useCache: false,
  _tzInfo: {},
  _day: NaN,
  year: NaN,
  month: NaN,
  date: NaN,
  hours: NaN,
  minutes: NaN,
  seconds: NaN,
  milliseconds: NaN,
  timezone: null,
  _dateProxy: Invalid Date,
  _timeProxy: NaN }
> var date = new tz.Date(null, 'Etc/UTC');
undefined
> date
{ _useCache: false,
  _tzInfo: {},
  _day: 4,
  year: 1970,
  month: 0,
  date: 1,
  hours: 0,
  minutes: 0,
  seconds: 0,
  milliseconds: 0,
  timezone: 'Etc/UTC',
  _dateProxy: Thu Jan 01 1970 00:00:00 GMT-0500 (EST),
  _timeProxy: 0 }
> 

But as you can see, the one using 'UTC' as the timezone isn't properly created. I tried running the test suite, but it looks like jasmine-node is buggy:

--(stuart@battra:pts/3)---(...src/hilary/node_modules/timezone-js)(win-compat)--
--(1141:Wed,07 Nov 12:$)-- jake test

Finished in 0 seconds
0 tests, 0 assertions, 0 failures
longlho commented 11 years ago

It's very unlikely this will support abbreviated tz name because of conflicts: New York time is EST, Australian time is also EST.

stuartf commented 11 years ago

Now that I look at the tests while not jet-lagged I see that they aren't using the 'UTC' abbreviation.