Comparing version 0.9.0 to 0.9.1
12
index.js
@@ -313,2 +313,10 @@ /** | ||
} | ||
// Sets day, month and year at once | ||
this.setAllDateFields = function setAllDateFields(y,mo,d) { | ||
zoneInfo.year = y - 1900; | ||
zoneInfo.month = mo; | ||
zoneInfo.dayOfMonth = d; | ||
return mktime.call(this); | ||
} | ||
// Sets the day of the month (from 1-31) in the current timezone | ||
@@ -426,5 +434,3 @@ this.setDate = function setDate(v) { | ||
if (relative) { | ||
this.setFullYear(y) | ||
this.setMonth(mo) | ||
this.setDate(d) | ||
this.setAllDateFields(y,mo,d) | ||
this.setHours(h) | ||
@@ -431,0 +437,0 @@ this.setMinutes(m) |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["date", "time", "time.h", "timezone", "setTimezone", "getTimezone"], | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -40,2 +40,20 @@ var should = require('should') | ||
}) | ||
it('should parse strings around 2038', function() { | ||
//Before threshold | ||
var d = new time.Date('2037-12-31 11:59:59 PM', 'UTC') | ||
d.getTime().should.equal(2145916799000) | ||
//After threshold | ||
d = new time.Date('2038-01-01 00:00:00 AM', 'UTC') | ||
d.getTime().should.equal(2145916800000) | ||
//Before threshold | ||
d = new time.Date('2038-1-19 03:14:06 AM', 'UTC') | ||
d.getTime().should.equal(2147483646000) | ||
//After threshold | ||
d = new time.Date('2038-1-19 03:14:07 AM', 'UTC') | ||
d.getTime().should.equal(2147483647000) | ||
}) | ||
}) | ||
@@ -117,3 +135,2 @@ | ||
, year = d.getFullYear() | ||
d.setTimezone('US/Pacific', true) | ||
@@ -137,3 +154,3 @@ | ||
it('should calculate correctly even between months', function () { | ||
it('should calculate correctly when UTC date is day after timezone date', function () { | ||
var forwards = { | ||
@@ -150,3 +167,8 @@ timezone: 'US/Pacific', hour: 22, minute: 47, | ||
d.toString().should.equal('Fri Feb 01 2013 06:47:01 GMT+0000 (UTC)'); | ||
}) | ||
it('should calculate correctly when UTC date is day before timezone date', function () { | ||
var d = new time.Date(2010, 0, 31, 19, 0, 0, 0, 'UTC'); | ||
d.toString().should.equal('Sun Jan 31 2010 19:00:00 GMT+0000 (UTC)') | ||
var backwards = { | ||
@@ -156,10 +178,17 @@ timezone: 'Australia/Sydney', hour: 2, minute: 47, | ||
}; | ||
var d = new time.Date( | ||
var d2 = new time.Date( | ||
backwards.year, backwards.month - 1, backwards.date, | ||
backwards.hour, backwards.minute, 1, 1, backwards.timezone | ||
); | ||
d.toString().should.equal('Fri Feb 01 2013 02:47:01 GMT+1100 (EST)'); | ||
d2.toString().should.equal('Fri Feb 01 2013 02:47:01 GMT+1100 (EST)'); | ||
d2.setTimezone('UTC'); | ||
d2.toString().should.equal('Thu Jan 31 2013 15:47:01 GMT+0000 (UTC)'); | ||
}) | ||
it('should calculate correctly on edge of months', function() { | ||
var d = new time.Date("2013-02-01 01:02:03", 'US/Pacific'); | ||
d.toString().should.equal('Fri Feb 01 2013 01:02:03 GMT-0800 (PST)'); | ||
d.setTimezone('UTC'); | ||
d.toString().should.equal('Thu Jan 31 2013 15:47:01 GMT+0000 (UTC)'); | ||
d.toString().should.equal('Fri Feb 01 2013 09:02:03 GMT+0000 (UTC)'); | ||
}) | ||
@@ -166,0 +195,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43545
771