Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
/ node-zoneinfo Public archive

Adding zonefile-based timezone support to Node.js Date objects.

License

Notifications You must be signed in to change notification settings

gsmcwhirter/node-zoneinfo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Adding zonefile-based timezone support to Node.js Date objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published