From c2d48c0082cdeb38eff3a3f8eb68ae7758fa4439 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Thu, 18 Apr 2013 19:55:37 +0200 Subject: fix timezone handling in js --- datastore-leveldb/wwwroot/src/ebus.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'datastore-leveldb/wwwroot/src') diff --git a/datastore-leveldb/wwwroot/src/ebus.js b/datastore-leveldb/wwwroot/src/ebus.js index 126db7d..ce4b876 100644 --- a/datastore-leveldb/wwwroot/src/ebus.js +++ b/datastore-leveldb/wwwroot/src/ebus.js @@ -9,8 +9,8 @@ d.week = 7 * d.day; d.month = 30.5 * d.day; d.now = new Date().getTime(); -var timeToUTC = function(d) { return d - new Date().getTimezoneOffset() * 60 * 1000; } -var timeToLocal = function(d) { return d + new Date().getTimezoneOffset() * 60 * 1000; } +var timeToUTC = function(d) { return d + new Date().getTimezoneOffset() * 60 * 1000; } +var timeToLocal = function(d) { return d - new Date().getTimezoneOffset() * 60 * 1000; } $(document).ready(function(){ var from = d.now - 1*d.day; @@ -85,7 +85,7 @@ $(document).ready(function(){ plotDetail = $.plot($("#ebusgraph"), datasetDetail, { - xaxis: { mode: "time", min: timeToUTC(from), max:timeToUTC(to) }, + xaxis: { mode: "time", min: timeToLocal(from), max:timeToLocal(to) }, yaxis: { min: -16, max: 100 }, legend: { show : true} }); @@ -99,8 +99,8 @@ $(document).ready(function(){ lines: { show: true, lineWidth: 1 }, shadowSize: 0 }, - xaxis: { mode: "time", min: timeToUTC(fromOverview), max:timeToUTC(toOverview) }, - yaxis: { ticks: [], min: -26, max: 100, autoscaleMargin: 0.1 }, + xaxis: { mode: "time", min: timeToLocal(fromOverview), max:timeToLocal(toOverview)}, + yaxis: { ticks: [], min: -26, max: 100, autoscaleMargin: 0.1 }, legend: { show: false }, selection: { mode: "x" } }); @@ -119,12 +119,12 @@ $(document).ready(function(){ unplotSensorOverview(sensorname); }; var plotSensorDetail = function(sensorConfig) { - $.getJSON("/api/range/"+escape(sensorConfig.sensorname)+"/"+timeToLocal(from)+"/"+timeToLocal(to)+"/800", + $.getJSON("/api/range/"+escape(sensorConfig.sensorname)+"/"+from+"/"+to+"/800", function(response) { console.log("foo"); if (!response.error) { response.data = response.data.map(function(d) { - return [ timeToUTC(d[0]), d[1] ]; + return [ timeToLocal(d[0]), d[1] ]; }); if (sensorConfig.mapFunc) { response.data = response.data.map( sensorConfig.mapFunc ) @@ -151,11 +151,11 @@ $(document).ready(function(){ }; var plotSensorOverview = function(sensorConfig) { - $.getJSON("api/range/"+escape(sensorConfig.sensorname)+"/"+timeToLocal(fromOverview)+"/"+timeToLocal(toOverview) + "/800", + $.getJSON("api/range/"+escape(sensorConfig.sensorname)+"/"+fromOverview+"/"+toOverview+ "/800", function(response) { if (!response.error) { response.data = response.data.map(function(d) { - return [ timeToUTC(d[0]), d[1] ]; + return [ timeToLocal(d[0]), d[1] ]; }); if (sensorConfig.mapFunc) { response.data = response.data.map( sensorConfig.mapFunc) @@ -182,15 +182,15 @@ $(document).ready(function(){ $("#overview").bind("plotselected", function (event, ranges) { range_from = Math.round(ranges.xaxis.from); - range_to = Math.round(ranges.xaxis.to); + range_to = Math.round(ranges.xaxis.to); // max selection range if (range_to - range_from > d.month) { // reset selection plotOverview.setSelection({xaxis: {'from': from, 'to': to}}, true); return; } else { - from = timeToLocal( range_from ); - to = timeToLocal( range_to ); + from = timeToUTC(range_from); + to = timeToUTC(range_to); } sensors = []; for (elem in datasetOverview) { -- cgit v1.2.1