-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Invalid dates are parsed as valid #1238
Comments
Yes, this is valid to js Date. You can use strict parsing to get what you need. https://day.js.org/docs/en/parse/string-format
|
Does Day.js strict parsing validate time formats as well? Following returns true. Should it return false since date string is missing the time?
|
well, seems this is something we've never think about it. this depends on how we define 'isValid', it should be a valid date-time? or valid and match the given format? |
IMHO, it should match the given format. Btw, I also found the following:
Both should be true. |
+1 |
using the strict boolean does not work here as well. |
@Gabee01 Your example returns the correct value (false) on my end: https://runkit.com/5fd149b2b4b41f001d9b4bf4/5fd149f5b4b41f001d9b4c26 |
@bornova I'm now wondering what have I done wrong at the time. I tested the validation several times, before giving up on this. It really looks like its working on runkit.. |
Do remember this dependent on CustomParseFormat plugin to work https://day.js.org/docs/en/parse/string-format |
@iamkun CustomParseFormat was really missing. thanks! |
@iamkun My issue still remains: Any plans to address this in the near future? I had to switch back to Moment.js for the time being. Thanks for all your effort in this library! |
🎉 This issue has been resolved in version 1.10.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@iamkun I think you should reopen This doesn't seem to be fixed, I want to migrate my lib from MomentJS to DayJS, so I'm fairly new to it but this is a bit of blocker to migrate. I expect the following lines to be both invalid and not be parseable/formattable // with version 1.10.4
console.log(dayjs('1900-02-33', 'YYYY-MM-DD', true).isValid()) // true but should be false 33 is not a valid date
console.log(dayjs('1900-02-33', 'MM/DD/YYYY', true).isValid()) // true but again should be false 33 is not valid and it also shouldn't be parseable
// trying to format them also works but changes the date completely
console.log(dayjs('1900-02-33', 'YYYY-MM-DD', true).format('MM/DD/YYYY')) // "03/05/1900"
console.log(dayjs('1900-02-33', 'MM/DD/YYYY', true).format('MM/DD/YYYY')) // "03/05/1900" If I take the same code and use MomentJS it's throwing EDIT I read the |
This should be reopened it's still happening for me
|
@rrdlpl I think you did the same mistake as I did which is to forget adding |
@ghiscoding I don;t understand what you meant. Could you please update my fiddle? |
For the people that still are struggling with this. As the other people mentioned you need
|
Why is this issue closed? I don't understand. I guess I am going back to moment. |
Extending I still get incorrect results (v1.11.3)
|
Invalid dates are parsed resulting in incorrect values
e.g,
const dt = dayjs('1993-51-11')
dt.isValid()
returnstrue
anddt.format('YYYY-MM-DD')
returns1997-03-11
const dt = dayjs('1993-51-41')
dt.isValid()
returnstrue
anddt.format('YYYY-MM-DD')
returns1997-04-10
infact
dayjs('1993-08-21', 'YYYY/MM/DD')
returns true for isValid()isValid() should return false for all these
Information
The text was updated successfully, but these errors were encountered: