Search code examples
chartstimezonedstzingchart

How to set time zone as float in Zing Chart?


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


Solution

  • 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.