Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Adding zonefile-based timezone support to Node.js Date objects.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
data
test
.gitignore
.travis.yml
LICENSE
README.md
countrycodes.js Adding the ability to request particular dates and times relative to …
index.js
package.json

README.md

node-zoneinfo

Build Status

This is a project intened to provide zonefile-based timezone supporting Date objects.

Installation

You can install this through npm:

npm install zoneinfo

Usage

An example of usage is as follows:

var sys = require('util');
var zoneinfo = require('zoneinfo'),
    TZDate = zoneinfo.TZDate,
    countrycodes = zoneinfo.countrycodes;

var d = new TZDate();
sys.puts(d);
//=> 2010-09-21 03:18:23 GMT
sys.puts(d.format("Y-m-d"));
//=> 2010-09-21
sys.puts(d.getTimezone());
//=> UTC
sys.puts(d.getTimezone(true));
//=> Etc/UTC
d.setTimezone("America/Denver");
sys.puts(d);
//=> 2010-09-20 21:18:23 GMT-0600
sys.puts(d.getTimezone());
//=> MDT
d.setTimezone("America/Los_Angeles");
sys.puts(d);
//=> 2010-09-20 20:18:23 GMT-0700
sys.puts(d.getTimezone());
//=> PDT
d.setTimezone("America/Phoenix");
sys.puts(d);
//=> 2010-09-20 20:18:23 GMT-0700
sys.puts(d.getTimezone());
//=> MST

zoneinfo.setDefaultTimezone("America/New_York");
var d = new TZDate("2010-11-08T16:00:00.000Z");
sys.puts(d);
//=> 2010-11-08 11:00:00 GMT-0500
sys.puts(d.getTimezone());
//=> EST
d.setTimezone("America/Denver");
sys.puts(d);
//=> 2010-11-08 09:00:00 GMT-0700
sys.puts(d.getTimezone());
//=> MST
d.setTimezone("America/Los_Angeles");
sys.puts(d);
//=> 2010-11-08 08:00:00 GMT-0800
sys.puts(d.getTimezone());
//=> PST
d.setTimezone("America/Phoenix");
sys.puts(d);
//=> 2010-11-08 09:00:00 GMT-0700
sys.puts(d.getTimezone());
//=> MST

sys.puts(sys.inspect(zoneinfo.listTimezones()));
//=> [array of all timezones on the system]
sys.puts(sys.inspect(zoneinfo.listTimezones("US")));
//=> [array of all US timezones on the system]

sys.puts(sys.inspect(countrycodes));
//=> [object of Name: Code pairs]

Tests

Tests that exist are written for Expresso (http://visionmedia.github.com/expresso/). To run them, install expresso and then run

expresso

Alternatively, you can run

expresso test/index.js

Or even better, run npm install and then

npm test

License

MIT (see LICENSE file)

Something went wrong with that request. Please try again.