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

2.19.x: The year setter changes the date to the last day of the month when overwriting a leap year #4258

Closed
mbeets-afro opened this issue Oct 20, 2017 · 1 comment
Labels

Comments

@mbeets-afro
Copy link

mbeets-afro commented 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:

const moment = require('moment');

const anotherMoment = moment('05 Jan 2017', 'DD MMM YYYY');
console.log(`${anotherMoment.format('YYYY-MM-DD')}`);
// outputs 2017-01-05

// Set the year to 2017 again
anotherMoment.year(2017);
console.log(`${anotherMoment.format('YYYY-MM-DD')}`);
// outputs 2017-01-05 -- no change as expected

// set year to a leap year
anotherMoment.year(2016);
console.log(`${anotherMoment.format('YYYY-MM-DD')}`);
// outputs 2016-01-05 -- year changes as expected

// set to the same leap year again
anotherMoment.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()).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

@mbeets-afro 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
@mattjohnsonpint
Copy link
Contributor

Dup #4024 and fix pending in #4255.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants