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

Something is wrong with historical timezone changes. #345

Closed
Reggino opened this issue May 24, 2016 · 5 comments
Closed

Something is wrong with historical timezone changes. #345

Reggino opened this issue May 24, 2016 · 5 comments
Labels

Comments

@Reggino
Copy link

Reggino commented May 24, 2016

Thanks for this, awesome work!

I did however run into an issue: Considers the following code:

var moment = require('moment-timezone');

var date1 = moment('1940-05-16T02:00:00+02:00');
console.log(date1.format());
console.log(date1.startOf('day').format());

var date2 = moment('1940-05-16T00:00:00.000Z');
date2.tz('Europe/Amsterdam');
console.log(date2.format());
console.log(date2.startOf('day').format());

Expected output:

1940-05-16T02:00:00+02:00
1940-05-16T00:00:00+02:00
1940-05-16T02:00:00+02:00
1940-05-16T00:00:00+02:00

Actual output (in latest version):

1940-05-16T02:00:00+02:00
1940-05-16T00:00:00+02:00
1940-05-16T02:00:00+02:00
1940-05-15T23:20:00+00:20

1940-05-16 is a special date: this day the timezone changed from +00:20 to +02:00, See Wikipeda. It looks like startOf doesn't honor the timezone change correctly after being adjusted to the Europe/Amsterdam timezone?

@Reggino Reggino changed the title Something is broken on historical timezone changes. Something is amiss on historical timezone changes. May 24, 2016
@Reggino Reggino changed the title Something is amiss on historical timezone changes. Something is wrong with historical timezone changes. May 24, 2016
@Reggino
Copy link
Author

Reggino commented May 24, 2016

To make things more complicated, see this page with more details on the change. DST started on that exact date. As a result, on 00:00:00 the clock turned forward 1:40 hour . Maybe the last result should be: 1940-05-16T01:40:00+02:00?

@Reggino
Copy link
Author

Reggino commented May 24, 2016

The same issue applies to other history related timezone changes. On 1937-07-01 the timezone changed from +01:19 to +01:20 in Europe/Amsterdam.

var moment = require('moment-timezone');

var date = moment('1937-07-01T00:00:00.000Z');
date.tz('Europe/Amsterdam');
console.log(date.format());
date.startOf('day');
console.log(date2.format());

has output

1937-07-01T01:20:00+01:20
1937-06-30T23:59:00+01:19

Where i expected

1937-07-01T01:20:00+01:20
1937-07-01T00:00:00+01:20

@mattjohnsonpint
Copy link
Contributor

Yes, it appears there is something going on here.

moment.tz('1940-05-15', 'Europe/Amsterdam').format()
// "1940-05-15T00:00:00+00:20"  (correct)
moment.tz('1940-05-15', 'Europe/Amsterdam').startOf('day').format()
// "1940-05-15T00:00:00+00:20"  (correct)
moment('1940-05-15T00:00:00Z').tz('Europe/Amsterdam').format()
// "1940-05-15T00:20:00+00:20"  (correct)
moment('1940-05-15T00:00:00Z').tz('Europe/Amsterdam').startOf('day').format()
// "1940-05-15T00:00:00+00:20"  (correct)

moment.tz('1940-05-16', 'Europe/Amsterdam').format()
// "1940-05-16T01:40:00+02:00"  (correct)
moment.tz('1940-05-16', 'Europe/Amsterdam').startOf('day').format()
// "1940-05-16T02:00:00+02:00"  (incorrect - should be "1940-05-16T01:40:00+02:00")
moment('1940-05-16T00:00:00Z').tz('Europe/Amsterdam').format()
// "1940-05-16T02:00:00+02:00"  (correct)
moment('1940-05-16T00:00:00Z').tz('Europe/Amsterdam').startOf('day').format()
// "1940-05-15T23:20:00+00:20"  (incorrect - should be "1940-05-16T01:40:00+02:00")

@mattjohnsonpint
Copy link
Contributor

Related issues: #327, moment/moment#3132, moment/moment#2749

@gilmoreorless
Copy link
Member

This was fixed in moment v2.24.0, as long as you're using a version of moment-timezone that includes the full 1940 dataset.

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

3 participants