auxesis / visage

Graph collectd metrics in the browser, backed by a JSON API
http://visage-app.com/
Other
381 stars 56 forks source link

Fix for time zone issue #146

Open sandeen opened 10 years ago

sandeen commented 10 years ago

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 commented 10 years ago

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) {
wrzasa commented 9 years ago

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

jessereynolds commented 9 years ago

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

jessereynolds commented 9 years ago

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