Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Calling moment.utc("2016-07-01").year(2013).toString() provides the wrong date #4238
Description of the Issue and Steps to Reproduce:
It seems like when setting the date to a date in the past and then setting the year to anything will push the outputted date to be at the end of the month.
If you call
I've reproduced this in Chrome 61 as well as in Node 5.10.1
Other information that may be helpful:
This seems to only be an issue if you are using a date from the year 2016. If you try
I can confirm that this is not an issue previous to moment 2.19.0+. It only is an issue from 2.19.0+
If you are reporting an issue, please run the following code in the environment you are using and include the output:
console.log( (new Date()).toString()) console.log((new Date()).toLocaleString()) console.log( (new Date()).getTimezoneOffset()) console.log( navigator.userAgent) console.log(moment.version)
In version 2.19.0 the function set$1() was changed.
Because of this change, setting a new year for a leap year moment, it always sets the last day of the month as date.
Current (incorrect) implementation
Because the special case is only needed for th 29th of Februar in leap years, the correct implementation should be:
Because this is a critical error it should be corrected as soon as possible.