Skip to content
This repository

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…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 data
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 countrycodes.js
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
README.md

node-zoneinfo

Description

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
Something went wrong with that request. Please try again.