visage icon indicating copy to clipboard operation
visage copied to clipboard

Fix for time zone issue

Open sandeen opened this issue 10 years ago • 4 comments

Hi, noticed the X axis on graphs doesn't reflect the current timezone. This patch works for me, to show data in the browser's local timezone.

sandeen avatar Nov 02 '14 03:11 sandeen

Ok. A bit of a hack, but this shows both the X axis and the tooltips in the local timezone:

--- ./lib/visage-app/public/javascripts/graph.js.orig       2014-11-02 09:02:17.652430060 -0600
+++ ./lib/visage-app/public/javascripts/graph.js    2014-11-02 10:08:34.219951653 -0600
@@ -127,6 +127,7 @@

 function formatDate(d) {
   var datetime = new Date(d)
+  datetime.increment('minute', datetime.getTimezoneOffset())
   return datetime.format("%Y-%m-%d %H:%M:%S UTC%z")
 }

@@ -272,11 +273,13 @@
         var host    = this.options.host
         var plugin  = this.options.plugin
         var data    = data ? data : this.response
+        var d = new Date();
+        var offset = d.getTimezoneOffset() * 60;

         $each(data[host][plugin], function(instance, instanceName) {
             $each(instance, function(metric, metricName) {
-                var start         = metric.start,
-                    finish        = metric.finish,
+                var start         = metric.start - offset,
+                    finish        = metric.finish - offset,
                     interval = (finish - start) / metric.data.length;

                 var data     = metric.data.map(function(value, index) {

sandeen avatar Nov 02 '14 16:11 sandeen

Any chance to merge this? It would be great not to have confusing time values on x axis!

wrzasa avatar Feb 28 '15 21:02 wrzasa

@sandeen will this work if the server process is not started in the UTC timezone?

jessereynolds avatar Mar 01 '15 09:03 jessereynolds

Also if you could submit this as a PR that would help

jessereynolds avatar Mar 01 '15 09:03 jessereynolds