-
Notifications
You must be signed in to change notification settings - Fork 7k
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 Date's are Still Reported as isValid() = true #3481
Comments
@mj1856 Sorry bud tried my best there :) I took a look at the new ticket, but I am having trouble seeing the relation. Regardless of how you handle .year() input, no matter how you get to it, shouldn't the isValid() function do a check to make sure a Date that is an "Invalid Date" does not return true on an isValid() check? I understand this could break a lot of current code, and probably should be saved for a major version bump, but just on a note of expected, intuitive, and sensible behavior, I would expect that when
then
|
@netpoetica, ultimately what will happen is that the first case will NOT occur. The result of that will be the current date, and valid will be true. Basically: moment().year("asdf").toString()
"Tue Oct 04 2016 08:03:33 GMT-0700"
moment().year("asdf").isValid()
true |
Thanks! I understand that, I think it makes sense to fix the issue with year input for sure. However, I still feel like there may be a separate issue:
Both of those have an internal prop from moment:
But for some reason, that isValid() function considers the first one to be valid. Not sure why isValid() would report true for one "Invalid Date" and false for another "Invalid Date", but it seems like a potential error with isValid(). Not trying to be a pain in the butt here, just trying to help make sure momentjs stays awesome :) |
I think you are confusing Consider: moment().year(2000).format() // "2000-10-04T09:47:16-07:00"
moment([2000]).format() // "2000-01-01T00:00:00-08:00" The first one is following your pattern, which keeps today's month, day, and time values. The second one constructs a moment using only a year, initializing the remaining fields to their earliest possible values. |
Also, the reason |
Description of the Issue and Steps to Reproduce:
As reported on Gitter, the issue is:
Usually, in JS when we're checking for valid dates, a date is only "valid" if it also is actually not an Invalid Date.
@mj1856 claimed in associated PR:
But I'm not sure how so.
Environment:
All
Other information that may be helpful:
The text was updated successfully, but these errors were encountered: