Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Error when using .json file for timezone data #46

Closed
mdedetrich opened this Issue · 29 comments

3 participants

@mdedetrich

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
Collaborator

Thanks for reporting I'll take a look :)

@mdedetrich

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

@longlho
Collaborator
@longlho
Collaborator

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

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
Collaborator
@longlho longlho referenced this issue from a commit
@longlho longlho more tests for issue #46 5e7b896
@longlho
Collaborator

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

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
Collaborator

What you can do is:

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

Let me know

@mdedetrich

Im getting a

Finished in 0 seconds
0 tests, 0 assertions, 0 failures
@longlho
Collaborator

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

@mdedetrich
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
Collaborator

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

@mdedetrich

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
Collaborator

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

@mdedetrich

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

@longlho
Collaborator

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

@mdedetrich

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
Collaborator

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

@mdedetrich

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
Owner

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

@mde
Owner

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

@longlho
Collaborator

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

@mdedetrich

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
Collaborator

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

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

@longlho
Collaborator

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

@mde
Owner
@longlho longlho closed this
@mdedetrich

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.