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
moment.date($day).month($month).year($year) behaves different than moment([$year, $month, $date]) #2725
Comments
Note that this
properly returns In fact moment mimics the behavior of JS date object. First you create The solution is to always set year, month, day, hour, minute, in this order to avoid issues like this. |
The fact about overflow handling is indeed documented: http://momentjs.com/docs/#/get-set/date/
Though the behavior in the corner case like yours is indeed surprising. |
I opened a PR in documentation repo the explains this common issue |
Yeah, I'm not sure this is fixable. Moment doesn't know that you're going to set the month, so it tries to set the day on the current month, which may or may not have a 31. It's ignorant of your intensions. I think @jakub-g's doc PR is good; let's do that. |
The date is parsed differently using these two setter methods.
When setting the date to
October 31, 2015
. The chained method returns2015-10-01
while the init method returns2015-10-31
JS Fiddle: http://jsfiddle.net/dgnjer7z/
The text was updated successfully, but these errors were encountered: