Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug in constructing dates from millisecond values with a specif…

…ied timezone.

Closes #18.
  • Loading branch information...
commit 240e76a645d0cb6a74af01349093a4313295321c 1 parent db7edd5
Seth Purcell authored committed
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 () {
Please sign in to comment.
Something went wrong with that request. Please try again.