-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add getNextTransition() and getLastTransition() functions
- Loading branch information
1 parent
12bcf20
commit 65d3629
Showing
3 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use strict"; | ||
|
||
var tz = require("../../").tz; | ||
var moment = require('../../index'); | ||
|
||
var guess = tz.prototype.guess; | ||
var now = Date.prototype.now; | ||
|
||
exports.getNextTransition = { | ||
setUp : function (done) { | ||
tz.prototype.guess = 'America/New_York'; | ||
Date.now = function() { return 1361481581996 }; | ||
done(); | ||
}, | ||
|
||
tearDown : function (done) { | ||
tz.prototype.guess = guess; | ||
Date.now = now; | ||
done(); | ||
}, | ||
|
||
"returns moment object with the date of next transition date relative to the moment or date object given as argument" : function (test) { | ||
var resultWithDate = tz.getNextTransition(new Date(1461481581996)); | ||
test.equal(resultWithDate.valueOf(), 1478412000000); | ||
|
||
var resultWithMoment = tz.getNextTransition(moment(1461481581996)); | ||
test.equal(resultWithMoment.valueOf(), 1478412000000); | ||
|
||
test.done(); | ||
}, | ||
|
||
"when no argument is given, returns moment object with the date of next transition date relative to current time" : function (test) { | ||
var result = tz.getNextTransition(); | ||
test.equal(result.valueOf(), 1362898800000); | ||
|
||
test.done(); | ||
} | ||
}; | ||
|
||
exports.getPreviousTransition = { | ||
setUp : function (done) { | ||
tz.prototype.guess = 'America/New_York'; | ||
Date.now = function() { return 1361481581996 }; | ||
done(); | ||
}, | ||
|
||
tearDown : function (done) { | ||
tz.prototype.guess = guess; | ||
Date.now = now; | ||
done(); | ||
}, | ||
|
||
"returns moment object with the date of previous transition date relative to the moment or date object given as argument" : function (test) { | ||
var resultWithDate = tz.getPreviousTransition(new Date(1461481581996)); | ||
test.equal(resultWithDate.valueOf(), 1457852400000); | ||
|
||
var resultWithMoment = tz.getPreviousTransition(moment(1461481581996)); | ||
test.equal(resultWithMoment.valueOf(), 1457852400000); | ||
|
||
test.done(); | ||
}, | ||
|
||
"when no argument is given, returns moment object with the date of previous transition date relative to current time" : function (test) { | ||
var result = tz.getPreviousTransition(); | ||
test.equal(result.valueOf(), 1352008800000); | ||
|
||
test.done(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters