Skip to content

Commit f370eab

Browse files
committed
Revert "Leap year and general date validation for isDate()"
This reverts commit 8eacd50.
1 parent f9d65f2 commit f370eab

File tree

2 files changed

+1
-38
lines changed

2 files changed

+1
-38
lines changed

test/validators.js

-11
Original file line numberDiff line numberDiff line change
@@ -855,26 +855,15 @@ describe('Validators', function () {
855855
validator: 'isDate'
856856
, valid: [
857857
'2011-08-04'
858-
, '2011-09-30'
859858
, '04. 08. 2011.'
860859
, '08/04/2011'
861860
, '2011.08.04'
862861
, '4. 8. 2011. GMT'
863-
, '2. 28. 2011. GMT'
864-
, '2. 29. 2008. GMT'
865-
, '2. 29. 1988. GMT'
866862
, '2011-08-04 12:00'
867-
, '2/29/24'
868-
, '2-29-24'
869863
]
870864
, invalid: [
871865
'foo'
872866
, '2011-foo-04'
873-
, '2011-09-31'
874-
, '2. 29. 1987. GMT'
875-
, '2. 29. 2011. GMT'
876-
, '2/29/25'
877-
, '2-29-25'
878867
, 'GMT'
879868
]
880869
});

validator.js

+1-27
Original file line numberDiff line numberDiff line change
@@ -450,33 +450,7 @@
450450
};
451451

452452
validator.isDate = function (str) {
453-
var normalizedDate = new Date((new Date(str)).toUTCString());
454-
var regularDay = String(normalizedDate.getDate());
455-
var utcDay = String(normalizedDate.getUTCDate());
456-
var dayOrYear, dayOrYearMatches, year;
457-
if (isNaN(Date.parse(normalizedDate))) {
458-
return false;
459-
}
460-
//check for valid double digits that could be late days
461-
//check for all matches since a string like '12/23' is a valid date
462-
dayOrYearMatches = str.match(/[23]\d(\D|$)/g);
463-
if (!dayOrYearMatches) {
464-
return true;
465-
}
466-
dayOrYear = dayOrYearMatches.map(function(match) {
467-
return match.slice(0,2);
468-
}).join('/');
469-
year = String(normalizedDate.getFullYear()).slice(-2);
470-
//local date and UTC date can differ, but both are valid, so check agains both
471-
if (dayOrYear === regularDay || dayOrYear === utcDay || dayOrYear === year) {
472-
return true;
473-
} else if ((dayOrYear === (regularDay + '/' + year)) || (dayOrYear === (year + '/' + regularDay))) {
474-
return true;
475-
} else if ((dayOrYear === (utcDay + '/' + year)) || (dayOrYear === (year + '/' + utcDay))) {
476-
return true;
477-
} else {
478-
return false;
479-
}
453+
return !isNaN(Date.parse(str));
480454
};
481455

482456
validator.isAfter = function (str, date) {

0 commit comments

Comments
 (0)