Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes bug in constructing dates from ms values with a timezone specified #18

Closed
wants to merge 1 commit into from

2 participants

@sp
sp commented

Pursuant to discussion on #8

Includes regression tests for existing constructor functionality.

@TooTallNate TooTallNate closed this pull request from a commit
Seth Purcell Fixed bug in constructing dates from millisecond values with a specif…
…ied timezone.

Closes #18.
240e76a
@TooTallNate
Owner

Looking real good @sp, merged in 240e76a, and published in v0.8.2. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 16, 2012
  1. Fixed bug in constructing dates from millisecond values with a specif…

    Seth Purcell authored
    …ied timezone.
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 2 deletions.
  1. +1 −0  .gitignore
  2. +2 −2 index.js
  3. +35 −0 test/date.js
View
1  .gitignore
@@ -1,2 +1,3 @@
/build
/node_modules
+.idea
View
4 index.js
@@ -498,8 +498,8 @@ function Date (year, month, day, hour, minute, second, millisecond, timezone) {
}
if (timezone) {
// set time given timezone relative to the currently set local time
- // (changing the internal "time" milliseconds value)
- d.setTimezone(timezone, true);
+ // (changing the internal "time" milliseconds value unless ms specified)
+ d.setTimezone(timezone, !(argc == 1 && typeof year === 'number'));
}
return d;
}
View
35 test/date.js
@@ -3,6 +3,41 @@ var should = require('should')
describe('Date', function () {
+ describe('constructor', function() {
+
+ it('should parse strings relative to TZ', function() {
+
+ var d = new time.Date('2012-1-12 02:00 PM', 'America/New_York')
+ d.getTime().should.equal(1326394800000);
+ d.getTimezone().should.equal('America/New_York');
+
+ d = new time.Date('2012-1-12 02:00 PM', 'America/Los_Angeles')
+ d.getTime().should.equal(1326405600000);
+ d.getTimezone().should.equal('America/Los_Angeles');
+ })
+
+ it('should interpret date parts relative to TZ', function() {
+
+ var d = new time.Date(2012, 0, 12, 14, 'America/New_York')
+ d.getTime().should.equal(1326394800000);
+ d.getTimezone().should.equal('America/New_York');
+
+ var d = new time.Date(2012, 0, 12, 14, 'America/Los_Angeles')
+ d.getTime().should.equal(1326405600000);
+ d.getTimezone().should.equal('America/Los_Angeles');
+ })
+
+ it('should accept milliseconds regardless of TZ', function() {
+
+ var d1 = new time.Date(1352005200000, 'America/New_York');
+ var d2 = new time.Date(1352005200000, 'America/Los_Angeles');
+
+ d1.getTime().should.equal(d2.getTime());
+ d1.getTimezone().should.equal('America/New_York');
+ d2.getTimezone().should.equal('America/Los_Angeles');
+ })
+ })
+
describe('#setTimezone()', function () {
beforeEach(function () {
Something went wrong with that request. Please try again.