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

Validate is incorrect #1488

Open
KimThi-madi opened this issue May 5, 2021 · 4 comments
Open

Validate is incorrect #1488

KimThi-madi opened this issue May 5, 2021 · 4 comments

Comments

@KimThi-madi
Copy link

Describe the bug
I'm trying to validate time by using isValid() function

case 1: dayjs("20:22:51"," HH:mm:ss ", true).isValid() ==> This return false
case 2: dayjs("20:22:61"," HH:mm:ss ", true).isValid() ==> This return true

Expected behavior
Case 1 should be returned true
Case 2 should be returned false

Information

  • Day.js Version 1.10.4
  • OS: ios
  • using in nodejs
  • Time zone: [e.g. GMT+07:00 ICT (Indochina Time)]
@ivansieder
Copy link

@KimThi-madi you have spaces around your your format (second parameter), I've reproduced it here and it works as it should: https://codesandbox.io/s/condescending-kalam-nct3j?file=/src/index.js

@nicewaytodoit
Copy link

Even one from example does not work anymore:
dayjs("1970-00-00", "YYYY-MM-DD", true).isValid() gives = true should be false
Version: 1.8.20

@nicewaytodoit
Copy link

nicewaytodoit commented May 16, 2021

Version: 1.10.4

dayjs('1970-00-00', 'YYYY-MM-DD').isValid(); // true
dayjs('1970-00-00', 'YYYY-MM-DD', true).isValid(); // true => should be false
dayjs('1970-00-00', 'YYYY-MM-DD', 'es', true).isValid(); // true => should be false

Even following is valid, month 90 with strict parse ?!

dayjs('1970-90-00', 'YYYY-MM-DD', true).isValid()
dayjs('1970-90-00', 'YYYY-MM-DD', 'en', true).isValid()

ok my bad again I forgot that I must do following for parsing to work:

import customParseFormat from "dayjs/plugin/customParseFormat";
dayjs.extend(customParseFormat)

@ivansieder
Copy link

exactly @nicewaytodoit, without the customParseFormat, the above examples won't be parsed strict. Please also be aware that your first example with version 1.8.20 doesn't use the latest 1.8.x version (which would be 1.8.36). I was able to reproduce the issue in 1.8.20, but it's fixed in the latest 1.8.x version

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

No branches or pull requests

3 participants