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.25.0+ Changed Add/Subtract Behavior for specific invalid input #6105

Open
oculus42 opened this issue Feb 28, 2023 · 0 comments
Open

2.25.0+ Changed Add/Subtract Behavior for specific invalid input #6105

oculus42 opened this issue Feb 28, 2023 · 0 comments

Comments

@oculus42
Copy link

oculus42 commented Feb 28, 2023

Describe the bug
Using .add() or .subtract() – possibly other methods – passing a new Date() or moment object as the first argument creates an invalid date. This is inconsistent with the behavior in 2.24.0 and inconsistent with other invalid inputs I tested.

To Reproduce
Steps to reproduce the behavior:

  1. moment('2023-01-01').add(new Date(), 'days').format() produces -0NaN--NaN--NaNT-NaN:-NaN:-NaN+00:00
  2. moment('2023-01-01').add({}, 'days').format() produces 2023-01-01T00:00:00-05:00 (for EST)

Expected behavior
A clear and concise description of what you expected to happen.
The behavior of .add() and .subtract() should be consistent for invalid data.

Screenshots
If applicable, add screenshots to help explain your problem.
moment-2 24 0-invalid-input
moment-2 29 4-invalid-input

Desktop (please complete the following information):

  • OS: macOS 13.2.1
  • Browser Chrome
  • Version 110.0.5481.177
    Also tested on Node 16.16.0 (see screenshots)

Moment-specific environment

  • The time zone setting of the machine the code is running on: EST
  • The time and date at which the code was run: 2023-02-28T16:45:00-05:00
  • Other libraries in use: none

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)

In RunJS:

'Tue Feb 28 2023 16:50:21 GMT-0500 (Eastern Standard Time)'
'2/28/2023, 4:50:21 PM'
300
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) runjs/2.7.5 Chrome/106.0.5249.168 Electron/21.2.2 Safari/537.36'
'2.29.4'

Additional context
This is not a serious concern for us, but it is a change that didn't appear to be documented, though I may have missed it. We discovered this as an invalid moment was provided to a datepicker and "broke" .isBefore() and .isAfter() checks for disabling out-of-range days.

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

No branches or pull requests

1 participant