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
Unnecessary deprecation warning #2535
Comments
You still need to supply one or more format strings. Moment can reliably test if a string can be parsed to a valid date in a particular format, but it cannot reliably test if any string is a date. There are many reasons for this, such as locale format differences. |
The point is that moment supports some default formats. So if you want to test if some string can be parsed by moment out of the box and the string is not parseable - then you get something printed in the console and a moment object with method .isValid(), which is strange and you cannot control it. It would be convenient to have a way to at least suppress dumping in the console - everything stays the same. best regards, |
I think the proposal in #2469 would cover that. Then you could do |
Thanks, |
Thanks for the proposal Matt, looks fine. best regards, |
I found this issue while googling for a solution to the same problem as @SVasilev. I just want to see if a string is parseable by Moment.js (not knowing the format in advance) without generating deprecation warnings. Would be wonderful if there were a class function instead of instance function, like moment.isValid() that just returns a boolean, rather than having to use the constructor first and get a deprecation warning. |
@odigity - Supply some format or formats that you might be expecting and you won't get a deprecation warning. Checking for any string that might be a date is an impossibility though, because with strings like 01/02/03 one cannot tell which order the fields are in. Also, please don't comment on old closed issues to ask for new features. Just open a new issue. Thanks. |
Why is this still an issue in 2019? I should not get a deprecation warning when the provided string is invalid if I'm calling .isValid(). I'm purposely throwing invalid strings when unit testing a function and I want it to throw without this warning cluttering my logs. Thanks. A limited workaround that I'm using for now is Note—this is a not a new feature request, but the original request from @SVasilev |
This issue is closed, not sure how to re-open The moment docs actually has an example https://momentjs.com/docs/ that'd produce this warning
I think that needs to be updated at least. |
Hello,
I am using moment js for my application and I faced a problem. So I have something like this:
As you see I am trying to use the isValid() method only for verification. Sometimes my input is not a valid date for moment js so it produces the "Deprecation warning: moment construction falls back to js Date." message.
I understand why you have put deprecation warning for the moment constructor but in my case I only want to use moment for verification. Shouldn't there be a way to use the isValid() functionality without getting the deprecation message. I need this because of some logging I have to handle.
Best regards,
Stefan.
The text was updated successfully, but these errors were encountered: