Skip to content
This repository was archived by the owner on Jan 26, 2020. It is now read-only.

Error when using .json file for timezone data #46

Closed
mdedetrich opened this issue Oct 10, 2012 · 29 comments
Closed

Error when using .json file for timezone data #46

mdedetrich opened this issue Oct 10, 2012 · 29 comments
Labels

Comments

@mdedetrich
Copy link

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
Copy link
Collaborator

longlho commented Oct 11, 2012

Thanks for reporting I'll take a look :)

@mdedetrich
Copy link
Author

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

@longlho
Copy link
Collaborator

longlho commented Oct 13, 2012

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 [email protected] 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
Copy link
Collaborator

longlho commented Oct 19, 2012

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
Copy link
Author

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 <[email protected]>",
  "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
Copy link
Collaborator

longlho commented Oct 20, 2012

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 [email protected] 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 [email protected]",
"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 added a commit that referenced this issue Oct 22, 2012
longlho added a commit that referenced this issue Oct 22, 2012
@longlho
Copy link
Collaborator

longlho commented Oct 22, 2012

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
Copy link
Author

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
Copy link
Collaborator

longlho commented Oct 23, 2012

What you can do is:

  • npm install -g jake
  • jake test:init
  • jake test

Let me know

@mdedetrich
Copy link
Author

Im getting a

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

@longlho
Copy link
Collaborator

longlho commented Oct 23, 2012

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

@mdedetrich
Copy link
Author

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
Copy link
Collaborator

longlho commented Oct 23, 2012

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

@mdedetrich
Copy link
Author

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
Copy link
Collaborator

longlho commented Oct 23, 2012

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

@mdedetrich
Copy link
Author

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

@longlho
Copy link
Collaborator

longlho commented Oct 23, 2012

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

@mdedetrich
Copy link
Author

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
Copy link
Collaborator

longlho commented Oct 23, 2012

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

@mdedetrich
Copy link
Author

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
Copy link
Owner

mde commented Oct 23, 2012

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

@mde
Copy link
Owner

mde commented Oct 23, 2012

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

@longlho
Copy link
Collaborator

longlho commented Oct 23, 2012

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

@mdedetrich
Copy link
Author

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
Copy link
Collaborator

longlho commented Oct 24, 2012

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
Copy link
Author

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

@longlho
Copy link
Collaborator

longlho commented Oct 29, 2012

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

@mde
Copy link
Owner

mde commented Oct 29, 2012

v0.4.4 just published to NPM.

On Sun, Oct 28, 2012 at 10:14 PM, Long Ho [email protected] 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//issues/46#issuecomment-9856547.

@longlho longlho closed this as completed Oct 29, 2012
@mdedetrich
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants