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

moment().startOf() fails during extra daylight savings hour #3580

Closed
clwainwright opened this issue Nov 7, 2016 · 5 comments · Fixed by #4338
Closed

moment().startOf() fails during extra daylight savings hour #3580

clwainwright opened this issue Nov 7, 2016 · 5 comments · Fixed by #4338

Comments

@clwainwright
Copy link

Description of the Issue and Steps to Reproduce:

Calling moment().startOf('hour') during the hour that's repeated when clocks are rolled back from daylight savings time yields the next hour, not the previous one.

For example, moment([2016,10,6]).add(1, 'hour').toDate() correctly yields Sun Nov 06 2016 01:00:00 GMT-0700 (PDT) (where my local timezone is US/Pacific), whereas moment([2016,10,6]).add(1, 'hour').startOf('hour').toDate() yields Sun Nov 06 2016 01:00:00 GMT-0800 (PST). This leads to some very odd behavior, like moment([2016,10,6]).add(1, 'hour').startOf('hour') <= moment([2016,10,6]).add(1, 'hour') yielding false. The same problem occurs for startOf('minute') and startOf('second').

Strangely, this does not seem to be a problem when setting the timezone explicitly using moment.tz([2016,10,6], 'US/Pacific').

Environment:

This is running moment version 2.15.2 directly off of the momentjs homepage in my browser's console. I'm running Safari 10.0.1 on macOS 10.12.1. I get the same problem on Firefox 49.0.2, but not on Chrome 54.0.2840.71.

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())
console.log((new Date()).toLocaleString())
console.log( (new Date()).getTimezoneOffset())
console.log( navigator.userAgent)
console.log(moment.version)
[Log] Mon Nov 07 2016 13:25:46 GMT-0800 (PST)
[Log] 11/7/2016, 1:25:46 PM
[Log] 480
[Log] Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14
[Log] 2.15.2
@mattjohnsonpint
Copy link
Contributor

This seems related to #1990, #2749 and #3132.

I'm not sure if it's an exact duplicate though, so leaving this open for now. Thanks for reporting.

@marwahaha
Copy link
Member

I'm trying to reproduce (on the momentjs.com website, which is now running 2.18.1) and the bug seems to be fixed.

image

Please re-open if you see this bug again.

@mattjohnsonpint
Copy link
Contributor

There's still something up here.

image

The last line should have stayed in GMT-0500 (Eastern Standard Time).

I also get the same results using .format() instead of .toDate(). Something in the startOf function is jumping back to the first instance of the repeated hour, even if we're within the second instance.

@mattjohnsonpint
Copy link
Contributor

(Chrome 57 latest on Win10, on Moment 2.18.1)

@tomasztomys
Copy link

The same problem here - moment 2.19.2, Chrome 62 on Win10

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

Successfully merging a pull request may close this issue.

4 participants