From 43e3ee74803dcf65f27b38cb758cad2980cb52d2 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 10 Dec 2010 15:35:27 +0100 Subject: [PATCH] fixed #32 (invalid timezone) --- frontend/javascripts/options.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/frontend/javascripts/options.js b/frontend/javascripts/options.js index 9ab5be5..4d17bc6 100644 --- a/frontend/javascripts/options.js +++ b/frontend/javascripts/options.js @@ -30,6 +30,7 @@ vz.options = { tuples: 300, refresh: false, defaultInterval: 1*24*60*60*1000, // 1 day + timezoneOffset: -(new Date().getTimezoneOffset() * 60*1000) }; vz.options.plot = { @@ -52,8 +53,29 @@ vz.options.plot = { mode: 'time', max: new Date().getTime(), // timeinterval to request min: new Date().getTime() - vz.options.defaultInterval, - timeformat: '%d.%b %h:%M', - monthNames: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'] + timeformat: '%d. %b %h:%M', + monthNames: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'], + tickFormatter: function(val, axis) { + var date = new Date(val + vz.options.timezoneOffset); /* add timezone offset */ + + /* TODO add period dependend timeformat + var delta = vz.options.plot.xaxis.max - vz.options.plot.xaxis.min; + + if (delta > 3*365*24*60*60*1000) // > 3 years + vz.options.plot.xaxis.timeformat = '%b %y'; + else if (delta > 31*24*60*60*1000) // > 1 month + vz.options.plot.xaxis.timeformat = '%d. %b'; + else if (delta > 14*24*60*60*1000) // > 2 weeks + vz.options.plot.xaxis.timeformat = '%d.%m'; + else if (delta > 24*60*60*1000) // > 1 day + vz.options.plot.xaxis.timeformat = '%d.%m %h:%M'; + else if (delta > 60*60*1000) // > 1 hour + vz.options.plot.xaxis.timeformat = '%h:%M'; + else // < 1 hour + format = '%h:%M:%S';*/ + + return $.plot.formatDate(date, vz.options.plot.xaxis.timeformat, vz.options.plot.xaxis.monthNames); + } }, yaxis: { }, selection: { mode: 'x' },