-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Add time zone support #5186
Comments
Is this being worked on? |
@kmcgaire not sure if @benmccann is looking at it or not |
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. |
Please consider moving to Luxon. Inspecting a simple ChartJS app reveals:
Huge. And that's mostly because of locale files.
|
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. |
This has been implemented by adding date adapters |
I took a look through the code, and it doesn't look like timezones are support with "vanilla" chartjs. The The solution seems to be to implement your own date adapter to provide this functionality however, according to #5960, the date adapter API is private, so a developer would need to track the date adapter source to code to ensure nothing breaks. Am I missing something? Because otherwise I'm not sure this should be closed yet. |
You can use https://github.com/chartjs/chartjs-adapter-luxon which supports time zones |
Has it been solved? It looks like it still doesnt work... |
I've found solution for my use case. Maybe someone will be interested. let diffUTC = (new Date().getTimezoneOffset()) * 60000; And then I use dt as X values. |
We should add time zone option that let's the user specify which timezone they'd like to use.
Things this could affect:
+0000
)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 (#4303) and
moment-timezone
is even larger, so I think we should avoid using it.The text was updated successfully, but these errors were encountered: