You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of the Issue
In version v2.19.0 and v2.19.1 if the date is in a leap year and you use the year setter to set the year to that same leap year again, the date portion is changed to the maximum date for that month.
ie if the date is 2016-01-05 and you set the year to 2016 again, the date changes to 2016-01-31
You'd expect the date to remain the same.
This does not occur in v2.18.1
perhaps related to (from the changelog): #4199 [bugfix] Fix year setter on leap years, fixes #4024
Steps to Reproduce:
install moment in local folder:
npm install moment@2.19.0 --save
contents of test.js file:
constmoment=require('moment');constanotherMoment=moment('05 Jan 2017','DD MMM YYYY');console.log(`${anotherMoment.format('YYYY-MM-DD')}`);// outputs 2017-01-05// Set the year to 2017 againanotherMoment.year(2017);console.log(`${anotherMoment.format('YYYY-MM-DD')}`);// outputs 2017-01-05 -- no change as expected// set year to a leap yearanotherMoment.year(2016);console.log(`${anotherMoment.format('YYYY-MM-DD')}`);// outputs 2016-01-05 -- year changes as expected// set to the same leap year againanotherMoment.year(2016);console.log(`${anotherMoment.format('YYYY-MM-DD')}`);// outputs 2016-01-31 -- date has changed!
Environment:
OS: Microsoft Windows 10 Pro
Version: 10.0.15063 Build 15063
Running in powershell as node test.js
Node: v6.11.1
Other information that may be helpful:
The time zone setting of the machine the code is running on
(UTC +02:00) Harare, Pretoria
The time and date at which the code was run
Fri Oct 20 2017 12:31:13 GMT+0200 (South Africa Standard Time)
Other libraries in use (TypeScript, Immutable.js, etc)
None
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())
Fri Oct 20 2017 12:31:13 GMT+0200 (South Africa Standard Time)
console.log( (new Date()).getTimezoneOffset())
-120
console.log( navigator.userAgent)
// not running in the browser
console.log(moment.version)
2.19.0
The text was updated successfully, but these errors were encountered:
mbeets-afro
changed the title
2.19.x: The year setter unnecessarily changes the date when overwriting a leap year
2.19.x: The year setter changes the date to the last day of the month when overwriting a leap year
Oct 20, 2017
Description of the Issue
In version v2.19.0 and v2.19.1 if the date is in a leap year and you use the year setter to set the year to that same leap year again, the date portion is changed to the maximum date for that month.
ie if the date is 2016-01-05 and you set the year to 2016 again, the date changes to 2016-01-31
You'd expect the date to remain the same.
This does not occur in v2.18.1
perhaps related to (from the changelog):
#4199 [bugfix] Fix year setter on leap years, fixes #4024
Steps to Reproduce:
install moment in local folder:
npm install moment@2.19.0 --save
contents of test.js file:
Environment:
OS: Microsoft Windows 10 Pro
Version: 10.0.15063 Build 15063
Running in powershell as
node test.js
Node: v6.11.1
Other information that may be helpful:
The time zone setting of the machine the code is running on
(UTC +02:00) Harare, Pretoria
The time and date at which the code was run
Fri Oct 20 2017 12:31:13 GMT+0200 (South Africa Standard Time)
Other libraries in use (TypeScript, Immutable.js, etc)
None
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())
Fri Oct 20 2017 12:31:13 GMT+0200 (South Africa Standard Time)
console.log((new Date()).toLocaleString())
10/20/2017, 12:31:13 PM
console.log( (new Date()).getTimezoneOffset())
-120
console.log( navigator.userAgent)
// not running in the browser
console.log(moment.version)
2.19.0
The text was updated successfully, but these errors were encountered: