Skip to content

Commit

Permalink
use UTC function for date normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
ravestack committed Aug 11, 2015
1 parent b1bc91f commit 9f62131
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,9 @@
};

validator.isDate = function (str) {
var rawDate = new Date(str);
var normalizedDate = new Date(rawDate.getTime() + rawDate.getTimezoneOffset()*60000);
var normalizedDate = new Date((new Date(str)).toUTCString());
var dayOrYear, dayOrYearMatches, day, year;
if (isNaN(Date.parse(rawDate))) {
if (isNaN(Date.parse(normalizedDate))) {
return false;
}
dayOrYearMatches = str.match(/[23]\d(\D|$)/g);
Expand All @@ -463,8 +462,9 @@
dayOrYear = dayOrYearMatches.map(function(match) {
return match.slice(0,2);
}).join('/');
day = String(normalizedDate.getDate());
day = String(normalizedDate.getUTCDate());
year = String(normalizedDate.getFullYear()).slice(-2);
console.log(dayOrYearMatches, dayOrYear, day, year);
if (dayOrYear === day || dayOrYear === year) {
return true;
} else if ((dayOrYear === (day + '/' + year)) || (dayOrYear === (year + '/' + day))) {
Expand Down

0 comments on commit 9f62131

Please sign in to comment.