Describe the bug
When repeatedly running this calculation: moment().add(1, 'years').diff(moment(), 'days') when the current date is in a year before a leap year (in my case, 2019/08/13), moment inconsistently returns 365 or 366. Adding .startOf('day') to each moment() will consistently return 366.
To Reproduce
Steps to reproduce the behavior:
- Execute
moment().add(1, 'years').diff(moment(), 'days') at least 4 times.
- Compare outputs, you'll see
365 and 366 inconsistently.
- Execute
moment().startOf('day').add(1, 'years').diff(moment().startOf('day'), 'days') at least 4 times.
- Compare outputs, you should see
366 each time.
Expected behavior
moment should consistently account for leap years when calculating day differences.
Desktop (please complete the following information):
- OS: Windows & MacOS
- Browser: Chrome
- Version 76
Moment-specific environment
- The time zone setting of the machine the code is running on: PST
- The time and date at which the code was run: See below
- Other libraries in use (TypeScript, Immutable.js, etc): Bug occurred in a CRA React app, but is replicable on https://momentjs.com in the console.
Please run the following code in your environment 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)
Output:
Tue Aug 13 2019 12:30:35 GMT-0700 (Pacific Daylight Time)
8/13/2019, 12:30:35 PM
420
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
2.24.0
Describe the bug
When repeatedly running this calculation:
moment().add(1, 'years').diff(moment(), 'days')when the current date is in a year before a leap year (in my case, 2019/08/13), moment inconsistently returns365or366. Adding.startOf('day')to eachmoment()will consistently return366.To Reproduce
Steps to reproduce the behavior:
moment().add(1, 'years').diff(moment(), 'days')at least 4 times.365and366inconsistently.moment().startOf('day').add(1, 'years').diff(moment().startOf('day'), 'days')at least 4 times.366each time.Expected behavior
moment should consistently account for leap years when calculating day differences.
Desktop (please complete the following information):
Moment-specific environment
Please run the following code in your environment and include the output:
Output: