Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid daylight saving time issue #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/suites/draft-04/keywords/formats/date-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ module.exports = function(config) {
sec >= 0 && sec <= 60 // it’s 60 during a leap second
)
{
var d = new Date(year, (month - 1) + 1); // the next month
var lastDay = new Date(d - 86400000);
if (mday <= lastDay.getDate()) {
var d = new Date("0000-01-01T00:00:00.000Z"); // Initialize a date in UTC time
d.setUTCFullYear(year);
d.setUTCMonth((month - 1) + 1); // the next month
var lastDay = new Date(d - 86400000); // the day before

if (mday <= lastDay.getUTCDate()) {

// [day-of-month is valid]

Expand Down
9 changes: 6 additions & 3 deletions lib/suites/draft-04/keywords/formats/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ module.exports = function(config) {
mday >= 1 && mday <= 31
)
{
var d = new Date(year, (month - 1) + 1); // the next month
var lastDay = new Date(d - 86400000);
if (mday <= lastDay.getDate()) {
var d = new Date("0000-01-01T00:00:00.000Z"); // Initialize a date in UTC time
d.setUTCFullYear(year);
d.setUTCMonth((month - 1) + 1); // the next month
var lastDay = new Date(d - 86400000); // the day before

if (mday <= lastDay.getUTCDate()) {
// [day-of-month is valid]
valid = true;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/our-tests/format.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"data": "1998-12-31T23:59:60Z",
"valid": true
},
{
"description": "matches schema (even on daylight saving time)",
"data": "2002-03-31T22:00:00.000Z",
"valid": true
},
{
"description": "does not match schema (invalid mday)",
"data": "2013-02-29T03:40:15Z",
Expand Down Expand Up @@ -51,6 +56,11 @@
"data": "2013-02-08",
"valid": true
},
{
"description": "matches schema (even on daylight saving time)",
"data": "2002-03-31",
"valid": true
},
{
"description": "does not match schema (invalid mday)",
"data": "2013-02-29",
Expand Down