question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add time zone support

See original GitHub issue

We should add time zone option that let’s the user specify which timezone they’d like to use.

Things this could affect:

  • We could have one time zone for parsing data and one used for formatting labels and tooltips (e.g. timestamps are provided in UTC, but you’d like to display in Eastern timezone)
  • Also used when we’re calculating major ticks / auto-ticks and try to align to the start of a minute, day, hour, etc. But when the start of the day is depends on the time zone.
  • In some cases we may be able to determine the timezone the user would like to use from the labels they’ve specified (e.g. +0000)
  • Unit tests are currently flaky because they depend on the timezone they’re being run in

Unfortunately JavaScript’s time zone support is pretty bad natively. E.g. there’s no way to create a Date object in a given timezone. Your only options are local system time or UTC time. We probably want to use only UTC dates or timestamps internally and convert to the proper time zone when needed for the cases listed above.

We would either need library support or would need to implement ourselves. In either case I think we should use Intl.DateTimeFormat APIs. We already get lots of complaints about the size of Moment.js (https://github.com/chartjs/Chart.js/issues/4303) and moment-timezone is even larger, so I think we should avoid using it.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pvfpvfcommented, May 23, 2018

Just to add, the global fix moment.tz.setDefault(“UTC”); works for me. But if I use chartjs-plugin-zoom and zoom in, the X axis times immediately revert to local ones.

1reaction
benmccanncommented, Mar 23, 2018

Yes. I think we should switch from Moment to either Luxon or date-fns in order to fix this. We couldn’t switch to Luxon until Chart.js 3.0 since Chart.js currently exposes Moment in it’s interface. I have a pending PR to add timezone support to date-fns and have been waiting for it to be reviewed the past couple month, but the library authors are not very responsive.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use different time zones in Calendar on Mac - Apple Support
In the Calendar app on your Mac, choose Calendar > Settings, then click Advanced. · Select “Turn on time zone support.” · Double-click...
Read more >
Add, remove, or change time zones - Microsoft Support
Click the File tab. Click Options. On the Calendar tab, under Time zones, select the Show a second time zone check box and,...
Read more >
How to add and use time zone support for Calendar events
Click Calendar from the top menu bar and select Preferences. Choose the Advanced tab. Mark the checkbox next to Turn on time zone...
Read more >
Tech Tip: Using Calendar Time Zone Support - MacSales.com
1) In iOS Calendar, tap the + button to create a new event · 2) Give the event a name and optional location...
Read more >
Work in different Calendar time zones - Google Support
In Google Calendar, go to Settings "" and then Settings. · Scroll to World Clock and check the Show world clock box. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found