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

Explicitly set moment timezone to detected one #123579

Closed
flash1293 opened this issue Jan 24, 2022 · 1 comment · Fixed by #188899
Closed

Explicitly set moment timezone to detected one #123579

flash1293 opened this issue Jan 24, 2022 · 1 comment · Fixed by #188899
Assignees
Labels
Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@flash1293
Copy link
Contributor

moment-timezone has a slightly weird behavior for dates right at the edge of a DST switch. If a time zone is explicitly set using setDefault, it's behaving differently even if the time zone is set to the one returned by guess:

Execute on a computer which is set to german time zone:
Screenshot 2022-01-24 at 10 56 13

        console.log(moment.tz.guess());
        console.log(moment('2021-03-27T03:00:00.000+02:00').add(moment.duration(1, 'day')).toISOString());
        moment.tz.setDefault(moment.tz.guess());
        console.log(moment('2021-03-27T03:00:00.000+02:00').add(moment.duration(1, 'day')).toISOString());
        moment.tz.setDefault();
        console.log(moment('2021-03-27T03:00:00.000+02:00').add(moment.duration(1, 'day')).toISOString());
Europe/Berlin
moment_service.ts:32 2021-03-28T01:00:00.000Z
moment_service.ts:34 2021-03-28T00:00:00.000Z
moment_service.ts:36 2021-03-28T01:00:00.000Z

This can cause issues in two situations:

To disambiguate these cases, I propose to always set the default timezone to the guessed one

if (zone) moment.tz.setDefault(zone.name);

      if (zone) {
        moment.tz.setDefault(zone.name);
      } else {
        moment.tz.setDefault(moment.tz.guess());
      }
@flash1293 flash1293 added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Jan 24, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants