-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix date/instant construction for years 0 <= y < 100
- Loading branch information
Showing
3 changed files
with
35 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
"use strict"; | ||
|
||
var createDate = function (y, m, d) { | ||
var date = new Date(Date.UTC(y, m, d)); | ||
if (y >= 0 && y < 100) { | ||
date.setUTCFullYear(y); | ||
} | ||
return date; | ||
} | ||
|
||
exports.canonicalDateImpl = function (ctor, y, m, d) { | ||
var date = new Date(Date.UTC(y, m - 1, d)); | ||
var date = createDate(y, m - 1, d); | ||
return ctor(date.getUTCFullYear())(date.getUTCMonth() + 1)(date.getUTCDate()); | ||
}; | ||
|
||
exports.calcWeekday = function (y, m, d) { | ||
return new Date(Date.UTC(y, m - 1, d)).getUTCDay(); | ||
return createDate(y, m - 1, d).getUTCDay(); | ||
}; | ||
|
||
exports.calcDiff = function (y1, m1, d1, y2, m2, d2) { | ||
var dt1 = new Date(Date.UTC(y1, m1 - 1, d1)); | ||
var dt2 = new Date(Date.UTC(y2, m2 - 1, d2)); | ||
var dt1 = createDate(y1, m1 - 1, d1); | ||
var dt2 = createDate(y2, m2 - 1, d2); | ||
return dt1.getTime() - dt2.getTime(); | ||
}; |
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