Skip to content

Commit

Permalink
Support YY format
Browse files Browse the repository at this point in the history
  • Loading branch information
CiprianS committed Jun 6, 2023
1 parent ec8b039 commit 21b07a6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ export default function isDate(input, options) {
dateObj[formatWord.charAt(0)] = dateWord;
}

return new Date(parseInt(dateObj.y), parseInt(dateObj.m)-1, parseInt(dateObj.d)).getDate() === +dateObj.d;
let fullYear = dateObj.y;

if (dateObj.y.length === 2) {
const currentYearLastTwoDigits = new Date().getFullYear() % 100;

if (parseInt(dateObj.y, 10) < currentYearLastTwoDigits) {
fullYear = `20${dateObj.y}`;
} else {
fullYear = `19${dateObj.y}`;
}
}

return new Date(`${fullYear}-${dateObj.m}-${dateObj.d}`).getDate() === +dateObj.d;
}

if (!options.strictMode) {
Expand Down

0 comments on commit 21b07a6

Please sign in to comment.