From 71ad99ff0321d09c260d7eac17fbeac637f9add0 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Fri, 13 Jun 2014 12:07:37 +0000 Subject: [PATCH] 2014-06-13 Sergio Martin * extensions/realtime_graphs.php extensions/realtime_graphs/realtime_graphs.js: Fix timezone differences in realtime graphs when client (browser) and server (console instance host) have different timezone. Now it takes always the server timezone. Ticket: #853 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10187 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 9 +++++++++ pandora_console/extensions/realtime_graphs.php | 3 +++ .../extensions/realtime_graphs/realtime_graphs.js | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index cf340bc2cf..13b5ae9ad5 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2014-06-13 Sergio Martin + + * extensions/realtime_graphs.php + extensions/realtime_graphs/realtime_graphs.js: Fix timezone + differences in realtime graphs when client (browser) and + server (console instance host) have different timezone. + Now it takes always the server timezone. + Ticket: #853 + 2014-06-13 Sergio Martin * include/functions_api.php: Add doc info to pagerduty diff --git a/pandora_console/extensions/realtime_graphs.php b/pandora_console/extensions/realtime_graphs.php index a55516e52b..5288607e6d 100644 --- a/pandora_console/extensions/realtime_graphs.php +++ b/pandora_console/extensions/realtime_graphs.php @@ -123,6 +123,9 @@ function pandora_realtime_graphs () { echo ''; echo ''; echo ''; + + // Store servers timezone offset to be retrieved from js + set_js_value('timezone_offset', date('Z', time())); } extensions_add_operation_menu_option (__('Realtime graphs'), null, null, "v1r1"); diff --git a/pandora_console/extensions/realtime_graphs/realtime_graphs.js b/pandora_console/extensions/realtime_graphs/realtime_graphs.js index 2b720a86e5..6907c5e8ee 100644 --- a/pandora_console/extensions/realtime_graphs/realtime_graphs.js +++ b/pandora_console/extensions/realtime_graphs/realtime_graphs.js @@ -5,6 +5,15 @@ var options = { xaxis: { tickFormatter: function (timestamp, axis) { var date = new Date(timestamp * 1000); + + var server_timezone_offset = get_php_value('timezone_offset'); + var local_timezone_offset = date.getTimezoneOffset()*60*-1; + + if (server_timezone_offset != local_timezone_offset) { + // If timezone of server and client is different, adjust the time to the server + date = new Date((timestamp + (server_timezone_offset - local_timezone_offset)) * 1000); + } + var hours = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()); var minutes = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()); var seconds = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());