You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/11/26 08:31:44 UTC

[GitHub] [echarts] NotAndD commented on issue #14453: Possibility to set specific timezone for time axis

NotAndD commented on issue #14453:
URL: https://github.com/apache/echarts/issues/14453#issuecomment-979783462


   We would be interested into this functionality as well, being able to specify a timezone and have everything rendered as if we were in that timezone (instead of the current browser timezone) would be great.
   
   Right now, similarly to the hack that was suggested, we do the same thing but with `moment.tz`.
   
   ```
   /**
    * Will hard-shift a timestamp so that, if rendered in current timezone, it will look as it is instead
    * into the desired timezone.
    */
   export function utcToZonedTime(utcTime: number, timezone: string) {
     const ourTimezone = moment.tz.guess();
     const ourOffsetInMillis = moment.utc(utcTime).tz(ourTimezone).utcOffset() * 60000;
     const givenTimezoneOffsetInMillis = moment.utc(utcTime).tz(timezone).utcOffset() * 60000;
   
     return utcTime + givenTimezoneOffsetInMillis - ourOffsetInMillis;
   }
   
   /**
    * Will revert what utcToZonedTime had done.
    */
   export function zonedTimeToUtc(zonedTime: number, timezone: string) {
     const ourTimezone = moment.tz.guess();
     const ourOffsetInMillis = moment.utc(zonedTime).tz(ourTimezone).utcOffset() * 60000;
     const givenTimezoneOffsetInMillis = moment.utc(zonedTime).tz(timezone).utcOffset() * 60000;
   
     return zonedTime - givenTimezoneOffsetInMillis + ourOffsetInMillis;
   }
   ```
   
   It kinda works.. but it would be way better if ECharts could do this on its own so that dates do not need to be modified.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org