Skip to content

Commit

Permalink
fix(isDate): hyphen before year is not allowed (#2381)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumit-tech-joshi authored Apr 27, 2024
1 parent eacccaf commit 0836777
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function zip(date, format) {
}

export default function isDate(input, options) {
if (typeof options === 'string') { // Allow backward compatbility for old format isDate(input [, format])
if (typeof options === 'string') { // Allow backward compatibility for old format isDate(input [, format])
options = merge({ format: options }, default_date_options);
} else {
options = merge(options, default_date_options);
Expand All @@ -49,6 +49,11 @@ export default function isDate(input, options) {

let fullYear = dateObj.y;

// Check if the year starts with a hyphen
if (fullYear.startsWith('-')) {
return false; // Hyphen before year is not allowed
}

if (dateObj.y.length === 2) {
const parsedYear = parseInt(dateObj.y, 10);

Expand Down
2 changes: 2 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13087,6 +13087,8 @@ describe('Validators', () => {
'2019-02-29', // non-leap year
'2020-04-31', // invalid date
'2020/03-15', // mixed delimiter
'-2020-04-19',
'-2023/05/24',
],
});
test({
Expand Down

0 comments on commit 0836777

Please sign in to comment.