Skip to content

Commit

Permalink
Simplify isDate()
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Oct 26, 2015
1 parent ea164c0 commit edb70fe
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,14 @@
if (isNaN(normalizedDate)) {
return false;
}
var utcDay = String(normalizedDate.getUTCDate());
// normalizedDate is in the user's timezone. Apply the input
// timezone offset to the date so that the year and day match
// the input
var timezoneDifference = normalizedDate.getTimezoneOffset() -
getTimezoneOffset(str);
normalizedDate = new Date(normalizedDate.getTime() +
60000 * timezoneDifference);
var regularDay = String(normalizedDate.getDate());
var day = String(normalizedDate.getDate());
var dayOrYear, dayOrYearMatches, year;
//check for valid double digits that could be late days
//check for all matches since a string like '12/23' is a valid date
Expand All @@ -533,16 +532,12 @@
return digitString.match(/\d+/g)[0];
}).join('/');
year = String(normalizedDate.getFullYear()).slice(-2);
//local date and UTC date can differ, but both are valid, so check agains both
if (dayOrYear === regularDay || dayOrYear === utcDay || dayOrYear === year) {
if (dayOrYear === day || dayOrYear === year) {
return true;
} else if ((dayOrYear === (regularDay + '/' + year)) || (dayOrYear === (year + '/' + regularDay))) {
} else if ((dayOrYear === (day + '/' + year)) || (dayOrYear === (year + '/' + day))) {
return true;
} else if ((dayOrYear === (utcDay + '/' + year)) || (dayOrYear === (year + '/' + utcDay))) {
return true;
} else {
return false;
}
return false;
};

validator.isAfter = function (str, date) {
Expand Down

0 comments on commit edb70fe

Please sign in to comment.