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
Changes from 1 commit
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
Prev Previous commit
fix(date): daylight saving time issue
To avoid daylight saving time issue, date should be instanciate regardless local time zone (i.e. in UTC time).
korvent committed Dec 7, 2015
commit b6a4fe7700e3b3fbab278862d40ad5e2f0932810
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
@@ -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]

9 changes: 6 additions & 3 deletions lib/suites/draft-04/keywords/formats/date.js
Original file line number Diff line number Diff line change
@@ -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;
}