6

How do I set the time zone as a float in the Zing chart?

 2 years ago
source link: https://www.codesd.com/item/how-do-i-set-the-time-zone-as-a-float-in-the-zing-chart.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How do I set the time zone as a float in the Zing chart?

advertisements

I use ZingChart to show data as a chart. In the char, I show the data following a time which I get from the server. ZingChart is set as default to follow client time.

I found we can set time zone in a chart only as integer value. However, some time zone are UTC+10:30, UTC+04:30...

So how can we set time zone to ZingChart showing correct time? And if that day has Daylight Saving Time, how should I correct it.

JSON scripts


Unfortunately it appears that ZingChart only supports whole-hour time zone offsets. Not only does this not account for time zones with fixed fractional-hour offsets, but it also doesn't properly account for time zones that use daylight saving time.

The example in the documentation says:

... For example, to set the timezone to Pacific Time, you would add: "timezone":-8.

This is incorrect, as Pacific time is only at UTC-8 during standard time. When it's in daylight time, it uses UTC-7.

This is a common mistake. See "Time Zone != Offset" in the timezone tag wiki. My recommendation to the ZingChart developers would be:

  1. Anywhere you support timezone:-8 you should also support fractional hour offsets such as timezone:5.5 or timezone:8.75.

  2. You should also support named time zone identifiers such as "America/Los_Angeles". To make them work, you'll need to provide a function that the developer can hook into. Don't try to implement the function directly, as there are several libraries already available for this. For example, a developer might combine ZingChart with moment-timezone by writing something like:

    zingchart.fnTZOffset = function(timestamp, timeZone) {
        return moment(timestamp).tz(timeZone).utcOffset() / 60;
    }
    
    

    ZingChart would invoke this function when timezone was a string and would apply the resulting offset to the specific data point.

Without support from ZingChart, there's not much you can do to properly support time zones.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK