Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

What is the exact ISO 8601 format for isDate() ? #2336

Open
ningji opened this issue Nov 2, 2023 · 4 comments
Open

What is the exact ISO 8601 format for isDate() ? #2336

ningji opened this issue Nov 2, 2023 · 4 comments
Labels

Comments

@ningji
Copy link

ningji commented Nov 2, 2023

Describe the bug
isDate("2020-06-15") is failing on 13.11.0, which is called from express-validator.
it used to work on 13.7.0.

const validator = require('validator');
const rt = validator.isDate('2022-06-15');
console.log(rt);

it prints false

Examples
isData("2020-06-15") was working on 13.7.0

I realized there's a change on 13.11.0
#2231
and changed my code to
isDate("2012-03-29T10:05:45-06:00") but still fails.

doesn't like "2012-03-29T10:05:45.000Z" either.

this format is from the online search on ISO 8601 date format
https://www.digi.com/resources/documentation/digidocs/90001488-13/reference/r_iso_8601_date_format.htm

My question is, what's the good example to pass isDate() ? thanks !

Additional context
Validator.js version: 13.11.0
Node.js version: 16.16.0
OS platform: macOS

@ningji ningji added the 🐛 bug label Nov 2, 2023
@ningji
Copy link
Author

ningji commented Nov 2, 2023

More info, i put some console.log at isDate@lib/isDate.js,
isData("2020-06-15") was working on 13.7,

now for 13.11 the argument input is "2020-06-15", options is undefined

@ningji
Copy link
Author

ningji commented Nov 3, 2023

More dbg info, the issue is from lib/isDate.js around line 120.
return new Date("".concat(fullYear, "-").concat(dateObj.m, "-").concat(dateObj.d)).getDate() === +dateObj.d;

in my test, the input is "2020-06-15",
"".concat(fullYear, "-").concat(dateObj.m, "-").concat(dateObj.d) is "2020-06-15T00:00:00.000Z".

but its getDate() returns 14 not 15.

I don't know how to fix it.

@ningji
Copy link
Author

ningji commented Nov 3, 2023

Ppl in stackoverflow mentioned it works fine in linux and win11.

@ningji
Copy link
Author

ningji commented Nov 3, 2023

Might be this one #2256

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant