diff --git a/backend/api/Api.php b/backend/api/Api.php index 089486a..def2115 100644 --- a/backend/api/Api.php +++ b/backend/api/Api.php @@ -2,6 +2,8 @@ namespace mbolli\nfsen_ng\api; +use DateTime; +use DateTimeZone; use mbolli\nfsen_ng\common\Config; use mbolli\nfsen_ng\common\Debug; @@ -290,6 +292,7 @@ public function config() { 'daemon_running' => $daemon_running, 'frontend' => $frontend, 'version' => Config::VERSION, + 'tz_offset' => (new DateTimeZone(date_default_timezone_get()))->getOffset(new DateTime('now', new DateTimeZone('UTC'))), ]; } diff --git a/frontend/js/nfsen-ng.js b/frontend/js/nfsen-ng.js index 5f7a954..8533f3e 100644 --- a/frontend/js/nfsen-ng.js +++ b/frontend/js/nfsen-ng.js @@ -738,9 +738,14 @@ $(document).ready(function() { } } + // Calculate the difference between the server and local timezone offsets + var serverTimezoneOffset = config.tz_offset * 60 * 60; + var localTimezoneOffset = new Date().getTimezoneOffset() * -60; + var timezoneOffset = serverTimezoneOffset - localTimezoneOffset; + // iterate over API result $.each(data.data, function (datetime, series) { - var position = [new Date(datetime * 1000)]; + var position = [new Date((parseInt(datetime) + timezoneOffset) * 1000)] ; // add all serie values to position array $.each(series, function (y, val) {