Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

isDate returns false for all strings #2389

Open
ElimuTek opened this issue Apr 15, 2024 · 10 comments
Open

isDate returns false for all strings #2389

ElimuTek opened this issue Apr 15, 2024 · 10 comments

Comments

@ElimuTek
Copy link

isDate returns false for all strings

isDate is always returning false, even for correctly formatted strings.

Examples
validator.isDate('2024-01-01', { format: 'YYYY-MM-DD', delimiters: ['-'] }); // false
validator.isDate("2024/01/01"); // false
validator.isDate(new Date('2024-01-01')); // true
validator.isDate(validator.toDate("1")); // true

The only way I was able to make the result come back true was to coerce the date into native date format with validator.isDate(new Date(${inputValue})) or validator.isDate(validator.toDate(inputValue)). This is not a viable workaround as the last example shows (returns valid for "1").
It seems like isDate is expecting an object, but the tool is intended for string validation.
Notably other validators like isBefore and isAfter are working correctly with the same date format YYYY/MM/DD, as a string.

Additional context
Validator.js version: 13.11.0
included via cdn: <script src="https://unpkg.com/validator@latest/validator.min.js"></script>
Node.js version: 18.16.0
OS platform: windows
isDate_example_screenshot

@land-bit
Copy link

land-bit commented Apr 16, 2024

This issue is interesting. I want to work on it.

@ElimuTek
Copy link
Author

ElimuTek commented Apr 16, 2024 via email

@land-bit
Copy link

land-bit commented Apr 18, 2024 via email

@PAllisonVSO
Copy link

PAllisonVSO commented May 2, 2024

I am also seeing this issue, using the latest version 13.11.0. It's a brand new install; just started using the package today. I do love how simple it is to implement.

If it helps; I pulled the code directly in to my system and it ran fine, but my original code is in typescript. I am wondering if there is a transpile issue somewhere along the way.

@alvyynm
Copy link

alvyynm commented May 20, 2024

Hmm.. I've tried all the examples provided by @ElimuTek and everything is working as expected.

I wasn't able to reproduce your issue. Could it be an issue with the way you're handling the data after submission?

You can perhaps share the code. That should help in reproduction and, eventually, troubleshooting.

import validator from "validator";

console.log(
  validator.isDate("2024-01-01", { format: "YYYY-MM-DD", delimiters: ["-"] })
); // true
console.log(validator.isDate("2024/01/01")); // true

@alvyynm
Copy link

alvyynm commented May 20, 2024

Can I have a look at the code @PAllisonVSO?

@PAllisonVSO
Copy link

I will try and put together a full working repository as I have time this week; work is currently super busy. Thanks for taking the time to respond!

@PAllisonVSO
Copy link

I just put together a test package and used version 13.12.0 and everything is working, so I tried it in the original package and it is working there as well; it must have gotten resolved. Thanks!

@SyedAzeemJaved
Copy link

Still facing the same issue.

Below is the code that I have:

    enforce("2024-01-01").isDate({
      format: 'YYYY-MM-DD'
    }); // false

@pano9000
Copy link
Contributor

@SyedAzeemJaved from your code aboce it looks like you are using vest and that one seems to be still depending on 13.9.0 - and there were a few updated to isDate since then (which fix, but also introduced some bugs as well though :-D)
https://github.com/search?q=repo%3Aealush%2Fvest+%22validator%22+language%3AJSON&type=code&l=JSON

but even If I try with 13.9.0 I still get "true" for the date you provided above.

in what timezone is the computer you ran the code above? just to rule out some strange edge case, that may have been fixed with #2257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants