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

Adding months to date across DST does not preserve hour #5825

Open
JBaczuk opened this issue Feb 4, 2021 · 5 comments
Open

Adding months to date across DST does not preserve hour #5825

JBaczuk opened this issue Feb 4, 2021 · 5 comments

Comments

@JBaczuk
Copy link

JBaczuk commented Feb 4, 2021

Describe the bug
If you add months to a date across DST, it does not preserve the hour as stated in the docs:

There are also special considerations to keep in mind when adding time that crosses over daylight saving time. If you are adding years, months, weeks, or days, the original hour will always match the added hour.

To Reproduce
Steps to reproduce the behavior:

> date = new Date()
2021-02-04T16:37:37.790Z
> moment(date).add(6, 'months').toISOString()
'2021-08-04T15:37:37.790Z'

Expected behavior

> date = new Date()
2021-02-04T16:37:37.790Z
> moment(date).add(6, 'months').toISOString()
'2021-08-04T16:37:37.790Z'

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS 11.2
  • Node: v14.15.4
  • Moment Version: 2.29.1

Moment-specific environment

  • The time zone setting of the machine the code is running on: America/Denver
  • The time and date at which the code was run: 1612456862588
  • Other libraries in use (TypeScript, Immutable.js, etc): n/a

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)

Result:

> console.log((new Date()).toString())
Thu Feb 04 2021 09:42:43 GMT-0700 (Mountain Standard Time)
> console.log((new Date()).toLocaleString())
2/4/2021, 9:42:43 AM
> console.log((new Date()).getTimezoneOffset())
420
> console.log(navigator.userAgent)
Uncaught ReferenceError: navigator is not defined
> console.log(moment.version)
2.29.1
@benzispawn
Copy link

I don't this issue on the 2.24.0
To Reproduce
`> date = new Date()
2021-02-17T15:37:07.718Z

moment(date).add(6, 'months').toISOString()
'2021-08-17T15:37:07.718Z'`

Result:
`> console.log((new Date()).toString())
Wed Feb 17 2021 12:35:22 GMT-0300 (Brasilia Standard Time)
undefined

console.log((new Date()).toLocaleString())
e()).getTimezoneOffset())
console.log(navigator.us2/17/2021, 12:35:22 PM
undefined
console.log((new Date()).getTimezoneOffset())
180
undefined
console.log(navigator.userAgent)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v0.4.7 Chrome/13.0.767.0 Safari/534.36
undefined
console.log(moment.version)
2.24.0`

@benzispawn
Copy link

I don't see the problem on 2.29.1 either
`> date = new Date()
2021-02-17T15:39:26.660Z

moment(date).add(6, 'months').toISOString()
'2021-08-17T15:39:26.660Z'
console.log((new Date()).toString())
Wed Feb 17 2021 12:39:46 GMT-0300 (Brasilia Standard Time)
undefined
console.log((new Date()).toLocaleString())
2/17/2021, 12:39:46 PM
undefined
console.log((new Date()).getTimezoneOffset())
180
undefined
console.log(navigator.userAgent)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v0.4.7 Chrome/13.0.767.0 Safari/534.36
undefined
console.log(moment.version)
2.29.1`

@JBaczuk
Copy link
Author

JBaczuk commented Feb 17, 2021

@benzispawn I think you are running it in your local time (Brasilia Standard Time) which does not observe daylight savings, correct? Therefore, you most likely wouldn't see this issue.

The important detail in the original ticket is that it was run in America/Denver timezone which does currently observe daylight savings.

@JBaczuk
Copy link
Author

JBaczuk commented Feb 22, 2021

@marwahaha Why was this closed?

@marwahaha marwahaha reopened this Feb 22, 2021
@jsimpson
Copy link

We are currently experiencing the same problem.

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

4 participants