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

unexpected isValid() == true for date #3720

Closed
aikomastboom opened this issue Jan 18, 2017 · 1 comment
Closed

unexpected isValid() == true for date #3720

aikomastboom opened this issue Jan 18, 2017 · 1 comment

Comments

@aikomastboom
Copy link

aikomastboom commented Jan 18, 2017

Description of the Issue and Steps to Reproduce:

var moment = require('moment');
var date = moment().set({'year':'year','month':'month','date':'day'});
date.isValid() // true

Please include the values of all variables used.

Environment:
moment@2.17.1",
$ node -v
v6.5.0

If you are reporting an issue, please run the following code in the environment you are using and include the output:

> var moment = require('moment');
> console.log( (new Date()).toString())
Wed Jan 18 2017 16:01:31 GMT+0100 (CET)
> console.log((new Date()).toLocaleString())
1/18/2017, 4:01:31 PM
> console.log( (new Date()).getTimezoneOffset())
-60
> console.log( navigator.userAgent)
ReferenceError: navigator is not defined
> console.log(moment.version)
2.17.1

Ensure your issue is isolated to moment. Issues involving third party tools will be closed unless submitted by the tool's author/maintainer.

$ node -e "console.log(require('moment')().set({'year':'year','month':'month','date':'day'}).isValid());"
true
@mattjohnsonpint
Copy link
Contributor

Thanks. This has been reported already. See #3483. A fix is pending with #3704 in the next release.

Also, if you are actually passing input in that way, you shouldn't start with moment() - that initializes everything with the current time. Instead, just pass the object in to begin with.

moment({'year': 2017, 'month': 0, 'date': 30}).isValid() // true
moment({'year': 'foo', 'month': 'bar', 'date': 'baz'}).isValid() // false

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

2 participants