Skip to content

Commit

Permalink
Prefer the Timezone functions over the TimeZone functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed May 2, 2011
1 parent 3cc3107 commit fc550ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -4,8 +4,8 @@ node-time


This module offers simple bindings for the C [time.h][] APIs.
It also offers an extended regular `Date` object with `getTimeZone()`
and `setTimeZone()` functions, which aren't normally part of JavaScript.
It also offers an extended regular `Date` object with `getTimezone()`
and `setTimezone()` functions, which aren't normally part of JavaScript.


Example
Expand All @@ -16,11 +16,11 @@ Example
// Create a new Date instance
var now = new time.Date();

now.setTimeZone("America/Los_Angeles");
now.setTimezone("America/Los_Angeles");
// `.getDate()`, `.getDay()`, `.getHours()`, etc.
// will return values according to UTC-8

now.setTimeZone("America/New_York");
now.setTimezone("America/New_York");
// `.getDate()`, `.getDay()`, `.getHours()`, etc.
// will return values according to UTC-5

Expand All @@ -37,20 +37,20 @@ magic _timezone_ capabilities!
var date = new time.Date();


#### date.setTimeZone(timezone) -> Undefined
#### date.setTimezone(timezone) -> Undefined

Sets the timezone for the `Date` instance. Calls to `getHours()`, `getDays()`,
`getMinutes()`, etc. will be relative to the timezone specified. This will throw
an Error if information for the desired timezone could not be found.

date.setTimeZone("America/Argentina/San_Juan");
date.setTimezone("America/Argentina/San_Juan");


#### date.getTimeZone() -> String
#### date.getTimezone() -> String

Returns a String containing the currently configured timezone for the date instance.

date.getTimeZone();
date.getTimezone();
// "America/Argentina/San_Juan"

### time() -> Number
Expand Down
13 changes: 7 additions & 6 deletions test.js
@@ -1,9 +1,7 @@
var assert = require('assert');

// The 'index.js' file extends "Date.prototype"
var time = require('./');


var d = new time.Date(Date.UTC(2011, 0, 1));

assert.equal(d.getUTCFullYear(), 2011);
Expand All @@ -12,7 +10,7 @@ assert.equal(d.getUTCDate(), 1);
console.log(d+'');


d.setTimeZone("UTC");
d.setTimezone("UTC");
console.log(d+'');
console.log("UTC Hours: " + d.getHours());
assert.equal(d.getUTCDay(), d.getDay());
Expand All @@ -26,20 +24,23 @@ assert.equal(d.getUTCSeconds(), d.getSeconds());
assert.equal(d.getTimezoneOffset(), 0);


d.setTimeZone("America/Los_Angeles");
d.setTimezone("America/Los_Angeles");
console.log(d+'');
console.log("LA Hours: " + d.getHours());
assert.equal(d.getHours(), 16);
assert.equal(d.getTimezoneOffset(), 480);


d.setTimeZone("America/New_York");
d.setTimezone("America/New_York");
console.log(d+'');
console.log("NY Hours: " + d.getHours());
assert.equal(d.getHours(), 19);


d.setTimeZone("US/Arizona");
d.setTimezone("US/Arizona");
console.log(d+'');
console.log("AZ Hours: " + d.getHours());
assert.equal(d.getHours(), 17);
assert.equal(d.getUTCHours(), 0);
d.setUTCHours(23);
assert.equal(d.getHours(), 16);

0 comments on commit fc550ed

Please sign in to comment.