mde / timezone-js

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

Error when using .json file for timezone data #46

Closed mdedetrich closed 11 years ago

mdedetrich commented 12 years ago

When using a .json file for timezone data instead of a folder generated through the

node node-preparse.js zoneFileDirectory > outputfile.json

command, I get the following error when setting a timezone

TypeError: Object 600 has no method 'match'
at parseTimeString (/Users/mdedetrich/temp/node_modules/timezone-js/src/date.js:449:21)
    at getBasicOffset (/Users/mdedetrich/temp/node_modules/timezone-js/src/date.js:494:17)
    at timezoneJS.timezone.getTzInfo (/Users/mdedetrich/temp/node_modules/timezone-js/src/date.js:855:17)
    at Object.timezoneJS.Date.getTimezoneInfo (/Users/mdedetrich/temp/node_modules/timezone-js/src/date.js:212:35)
    at Object.timezoneJS.Date.getTimezoneOffset (/Users/mdedetrich/temp/node_modules/timezone-js/src/date.js:201:50)
    at Object.timezoneJS.Date.getUTCDateProxy (/Users/mdedetrich/temp/node_modules/timezone-js/src/date.js:331:50)
    at Object.timezoneJS.Date.getUTCMinutes (/Users/mdedetrich/temp/node_modules/timezone-js/src/date.js:227:46)
    at Object.timezoneJS.Date.setTimezone (/Users/mdedetrich/temp/node_modules/timezone-js/src/date.js:358:33)

600 happens to be the timezone for 'Pacific/Honolulu'. It appears that when the JSON file is parsed, timezone-js doesn't appear to convert the objects to a string, they instead remain as objects. Here is the tz.json I am using (that was generated through the above command) https://dl.dropbox.com/u/11630011/tz.json.

Also this is what my transport function looks like

timezoneJS.timezone.transport = function(opts) {
  return fs.readFileSync(opts.url, 'utf8');
};

This is being run on the latest version of node.js

longlho commented 12 years ago

Thanks for reporting I'll take a look :)

mdedetrich commented 12 years ago

Is there an ETA for when this will be fixed (its somewhat urgent for my end)

longlho commented 12 years ago

Will try to do it this weekend. If u have a patch feel free to submit a pull request.

Long Ho Web Developer iHeartRadio/Clear Channel Radio

On Oct 12, 2012, at 10:21 PM, mdedetrich notifications@github.com wrote:

Is there an ETA for when this will be fixed (its somewhat urgent for my end)

— Reply to this email directly or view it on GitHub.

longlho commented 12 years ago

Sorry I've been busy. Can you provide a complete workflow for this use case? What steps did you take? What did you mean by "setting a timezone"?

mdedetrich commented 12 years ago

So basically, I followed the steps here to get the tzdata

# Create the /tz directory
mkdir tz

# Download the latest Olson files
curl ftp://ftp.iana.org/tz/tzdata-latest.tar.gz -o tz/tzdata-latest.tar.gz

# Expand the files
tar -xvzf tz/tzdata-latest.tar.gz -C tz

# Optionally, you can remove the downloaded archives.
rm tz/tzdata-latest.tar.gz

I then downloaded the date.js and node-preparse.js files into a single directory, and ran node node-prepare.js to generate a tz.json file (which I uploaded and linked to before). I then placed the tz.json file in the same directory as a node project to test out the timezone-js, library. The package.json file is this

{
  "name": "date-test",
  "version": "0.0.1-114",
  "author": "Matthew de Detrich <mdedetrich@gmail.com>",
  "private": true,
  "engines": {
    "node": ">= 0.6.0"
  },
  "dependencies": {
    "moment" : "1.7.2",
    "timezone-js": "0.4.3"
  }
}

I then created a coffee file as detailed below

moment = require 'moment'
timezoneJS = require 'timezone-js'
fs = require 'fs'

_tz = timezoneJS.timezone
_tz.loadingScheme = _tz.loadingSchemes.MANUAL_LOAD;

timezoneJS.timezone.transport = (opts)->
   fs.readFileSync(opts.url, 'utf8')

_tz.loadZoneJSONData('tz.json', true);

dt = new timezoneJS.Date()
dt.setTimezone('America/Chicago')

console.info dt

And ran it with coffee test.coffee as per normal, and I get the error message described in the original post.

Im 99% sure its due to how the tz.json file data is being parsed, maybe something has changed since then?

longlho commented 12 years ago

Thanks a lot. It's prob sth to do with its internal cache. I'll try to debug it.

Long Ho Web Developer iHeartRadio/Clear Channel Radio

On Oct 19, 2012, at 10:43 PM, mdedetrich notifications@github.com wrote:

So basically, I followed the steps here to get the tzdata

Create the /tz directory

mkdir tz

Download the latest Olson files

curl ftp://ftp.iana.org/tz/tzdata-latest.tar.gz -o tz/tzdata-latest.tar.gz

Expand the files

tar -xvzf tz/tzdata-latest.tar.gz -C tz

Optionally, you can remove the downloaded archives.

rm tz/tzdata-latest.tar.gz I then downloaded the date.js and node-preparse.js files into a single directory, and ran node node-prepare.js to generate a tz.json file (which I uploaded and linked to before). I then placed the tz.json file in the same directory as a node project to test out the timezone-js, library. The package.json file is this

{ "name": "date-test", "version": "0.0.1-114", "author": "Matthew de Detrich mdedetrich@gmail.com", "private": true, "engines": { "node": ">= 0.6.0" }, "dependencies": { "moment" : "1.7.2", "timezone-js": "0.4.3" } } I then created a coffee file as detailed below

moment = require 'moment' timezoneJS = require 'timezone-js' fs = require 'fs'

_tz = timezoneJS.timezone _tz.loadingScheme = _tz.loadingSchemes.MANUAL_LOAD;

timezoneJS.timezone.transport = (opts)-> fs.readFileSync(opts.url, 'utf8')

_tz.loadZoneJSONData('tz.json', true);

dt = new timezoneJS.Date() dt.setTimezone('America/Chicago')

console.info dt And ran it with coffee test.coffee as per normal, and I get the error message described above

— Reply to this email directly or view it on GitHub.

longlho commented 12 years ago

I can't seem to reproduce it. I've added a test for your case in tz.manual.spec.js in the spec folder. I'm testing it against master btw, not 0.4.3. If the issue doesn't happen in master then I'll ask @mde to publish a new version 0.4.4

mdedetrich commented 12 years ago

I have just installed jake, how do you use jake to run the tests (I am reading the documentation however you don't seem to have any tests per say?)

longlho commented 12 years ago

What you can do is:

Let me know

mdedetrich commented 12 years ago

Im getting a

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

hmm that's weird. Can you try npm test then?

mdedetrich commented 12 years ago
Removing old timezone data.
rm -rf lib/tz
Downloading new timezone data ...
Expanding archive ...
Retrieved new timezone data
path.existsSync is now called `fs.existsSync`.

Finished in 0 seconds
0 tests, 0 assertions, 0 failures

I am doing this in the timezone-js node_modules directory

longlho commented 12 years ago

hmm are you sure you got the master branch? The console output is missing something

mdedetrich commented 12 years ago

Ok, got this

Failures:

  1) should take in millis as constructor
   Message:

     Expected '1970-01-01T01:00:00.000Z' to equal '1970-01-01T00:00:00.000Z'.
   Stacktrace:

     Error: Expected '1970-01-01T01:00:00.000Z' to equal '1970-01-01T00:00:00.000Z'.
    at new jasmine.ExpectationResult (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:102:32)
    at null.toEqual (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1171:29)
    at null.<anonymous> (/Users/mdedetrich/temp/masterbranch/spec/date.spec.js:113:25)
    at jasmine.Block.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at jasmine.Queue.start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
    at jasmine.Spec.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at onComplete (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1786:18)
    at jasmine.Spec.finish (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2044:5)

  2) should take in Date object as constructor
   Message:
     Expected '1970-01-01T01:00:00.000Z' to equal '1970-01-01T00:00:00.000Z'.
   Stacktrace:

     Error: Expected '1970-01-01T01:00:00.000Z' to equal '1970-01-01T00:00:00.000Z'.
    at new jasmine.ExpectationResult (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:102:32)
    at null.toEqual (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1171:29)
    at null.<anonymous> (/Users/mdedetrich/temp/masterbranch/spec/date.spec.js:121:25)
    at jasmine.Block.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at jasmine.Queue.start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
    at jasmine.Spec.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at onComplete (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1786:18)
    at jasmine.Spec.finish (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2044:5)

  3) should take in millis and tz as constructor
   Message:
     Expected 3600000 to equal 0.
   Stacktrace:
     Error: Expected 3600000 to equal 0.
    at new jasmine.ExpectationResult (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:102:32)
    at null.toEqual (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1171:29)
    at null.<anonymous> (/Users/mdedetrich/temp/masterbranch/spec/date.spec.js:128:26)
    at jasmine.Block.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at jasmine.Queue.start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
    at jasmine.Spec.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at onComplete (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1786:18)
    at jasmine.Spec.finish (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2044:5)

  4) should take in Date object as constructor
   Message:
     Expected 3600000 to equal 0.
   Stacktrace:
     Error: Expected 3600000 to equal 0.
    at new jasmine.ExpectationResult (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:102:32)
    at null.toEqual (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1171:29)
    at null.<anonymous> (/Users/mdedetrich/temp/masterbranch/spec/date.spec.js:135:26)
    at jasmine.Block.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at jasmine.Queue.start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
    at jasmine.Spec.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at onComplete (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1786:18)
    at jasmine.Spec.finish (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2044:5)

  5) should be able to clone itself
   Message:
     Expected 3600000 to equal 7200000.
   Stacktrace:
     Error: Expected 3600000 to equal 7200000.
    at new jasmine.ExpectationResult (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:102:32)
    at null.toEqual (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1171:29)
    at null.<anonymous> (/Users/mdedetrich/temp/masterbranch/spec/date.spec.js:207:26)
    at jasmine.Block.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at jasmine.Queue.start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
    at jasmine.Spec.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at onComplete (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1786:18)
    at jasmine.Spec.finish (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2044:5)

  6) should be able to clone itself
   Message:
     Expected '1969-12-31 19:00:00' to equal '1969-12-31 20:00:00'.
   Stacktrace:
     Error: Expected '1969-12-31 19:00:00' to equal '1969-12-31 20:00:00'.
    at new jasmine.ExpectationResult (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:102:32)
    at null.toEqual (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1171:29)
    at null.<anonymous> (/Users/mdedetrich/temp/masterbranch/spec/date.spec.js:208:27)
    at jasmine.Block.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at jasmine.Queue.start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
    at jasmine.Spec.execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14)
    at jasmine.Queue.next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at onComplete (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1786:18)
    at jasmine.Spec.finish (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2044:5)

Finished in 3.465 seconds
51 tests, 130 assertions, 6 failures

jake aborted.
Error: Process exited with error.
    at fail (/usr/local/lib/node_modules/jake/lib/api.js:221:18)
(See full trace by running task with --trace)
longlho commented 12 years ago

What node version were you using? Also what timezone and OS?

mdedetrich commented 12 years ago

Node version is v0.8.6 OS is Mac OSX Lion 10.8.2 My timezone is 'Australia/Sydney'

longlho commented 12 years ago

Hmm interesting. It seems to be another bug then, but the manual test seems to pass on your box, right?

mdedetrich commented 12 years ago

Well I am not sure, this is the whole output of running the tests (https://gist.github.com/7ffcff2add1aba65d106) and it doesn't specify if it ran the manual test or not (I don't use jake so no idea)

longlho commented 12 years ago

You can try manually running that test jasmine-node spec/tz.manual.spec.js

mdedetrich commented 12 years ago

Ok, running jasmine-node spec/tz.manual.spec.js gives me this

Finished in 0.035 seconds
1 test, 6 assertions, 0 failures

So that seems to have worked

mde commented 12 years ago

Could be a bug with Jake's builtin TestTask. It shouldn't step on anything user-defined, but I'll make sure.

mde commented 12 years ago

Nope, doesn't appear to be that. I'll take a look anyway and see why the tests don't run.

longlho commented 12 years ago

Might be a bug in Chrome/V8 itself, since Firefox current tz in Australia is EDT, but for Chrome/V8 it's EST.

mdedetrich commented 12 years ago

Isn't the point of timezone-js is that its completely architecture independent? (in which case user defined settings should not make a difference)

longlho commented 12 years ago

timezone-js is a layer on top of Date, which is JS-engine-dependent so it'd be very hard to be architecture-independent unless it talks to OS-level clock libraries.

mdedetrich commented 11 years ago

Is there an eta on when the package will be updated on npm?

longlho commented 11 years ago

@mde it's been a while since we up'ed the package can we do that?

mde commented 11 years ago

v0.4.4 just published to NPM.

On Sun, Oct 28, 2012 at 10:14 PM, Long Ho notifications@github.com wrote:

@mde https://github.com/mde it's been a while since we up'ed the package can we do that?

— Reply to this email directly or view it on GitHubhttps://github.com/mde/timezone-js/issues/46#issuecomment-9856547.

mdedetrich commented 11 years ago

I can confirm that the latest updated solved the problem, thanks!