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

Showing date/times in user's local timezone? #99

Closed
ammgws opened this issue Feb 10, 2017 · 6 comments
Closed

Showing date/times in user's local timezone? #99

ammgws opened this issue Feb 10, 2017 · 6 comments

Comments

@ammgws
Copy link

ammgws commented Feb 10, 2017

I have data from an API that returns datetime strings in UTC. Example dataset here

When plotting these data I want the datetimes to be shown in the user's local timezone, not UTC.
Is this possible using amcharts?

(I thought about writing a postProcess function that loops through the whole dataset and updates each datetime string to an adjusted datetime string or object, but it sounds like a kludge..)

@martynasma
Copy link
Collaborator

I know this might seem counter-intuitive but the fix would be to remove "Data date format" (or dataDateFormat in config) setting. When you have that set, the chart parses the string dates and creates Date objects with the hour on user's machine, hence all times display in UTC.

When you remove date formatting option, the JavaScript's native parser takes over, which will parse date using correct time-zone info.

However, better option would be to supply your dates in data as timestamps.

@ammgws
Copy link
Author

ammgws commented Feb 13, 2017

Removing dataDataFormat did the trick, thank you!
Perhaps it could be mentioned in the docs for AmSerialChart/dataDateFormat or the demo charts page?
 
 

However, better option would be to supply your dates in data as timestamps.

By this do you mean it is better to supply dates in epoch time rather than in ISO8601 format?
(Is it because it is less performance intensive to parse?)

@martynasma
Copy link
Collaborator

Sorry, your reply slipped through the cracks.

Yes, this way there's no expensive string date parsing. And some older browsers will have issues in parsing string dates.

The timestamp gets supplied directly to Date constructor, which works on all browsers, even ancient ones.

And timestamps are always in UTC.

@ammgws
Copy link
Author

ammgws commented Feb 22, 2017

Cheers for the explanation. I'll have a go sometime in the near future and see if I observe any gains.

@ammgws ammgws closed this as completed Feb 22, 2017
@morrow95
Copy link

"Removing dataDataFormat did the trick, thank you!"

Can you explain this in a little more detail? I am having the same issue. I am passing UTC, but when the chart shows it is always converted to the computer's timezone. I would prefer passing the data how it is, or in a timezone of my choosing even, not changing my data at all.

@ammgws
Copy link
Author

ammgws commented May 30, 2018

My problem was the opposite to yours; I wanted to pass in UTC and display it in the client's timezone.
Anyway, check out the example graph here.
The dataset has three datetimes, given in UTC, and the graph is also in UTC.
However if you remove the dataDataFormat parameter, the graph will now show in your computer's timezone.

Thus if you want to display your data as-is, you should make sure the dataDateFormat line is there, otherwise it will show up as the client's timezone:
image

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

No branches or pull requests

3 participants