From 4c79d5b5a624ef0e30b0002c9e22a97e6a8ea6e3 Mon Sep 17 00:00:00 2001 From: "peng.jianhua" Date: Thu, 25 Jan 2018 13:27:56 +0800 Subject: [PATCH 1/1] KYLIN-3069 Add proper time zone support to the WebUI instead of GMT/PST kludge --- webapp/app/js/filters/filter.js | 42 ++++++++++--------------------- webapp/app/js/services/kylinProperties.js | 3 +++ webapp/app/partials/query/query.html | 2 +- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/webapp/app/js/filters/filter.js b/webapp/app/js/filters/filter.js index 72bb50245..0f8382dbf 100755 --- a/webapp/app/js/filters/filter.js +++ b/webapp/app/js/filters/filter.js @@ -122,7 +122,6 @@ KylinApp } }).filter('utcToConfigTimeZone', function ($filter, kylinConfig) { - var gmttimezone; //convert GMT+0 time to specified Timezone return function (item, timezone, format) { @@ -132,39 +131,24 @@ KylinApp } if (angular.isUndefined(timezone) || timezone === '') { - timezone = kylinConfig.getTimeZone() == "" ? 'PST' : kylinConfig.getTimeZone(); - } - if (angular.isUndefined(format) || format === '') { - format = "yyyy-MM-dd HH:mm:ss"; + timezone = kylinConfig.getTimeZone() == "" ? 'UTC' : kylinConfig.getTimeZone(); } - //convert short name timezone to GMT - switch (timezone) { - //convert PST to GMT - case "PST": - gmttimezone = "GMT-8"; - break; - default: - gmttimezone = timezone; + if (angular.isUndefined(format) || format === '') { + format = "YYYY-MM-DD HH:mm:ss z"; } - var localOffset = new Date().getTimezoneOffset(); - var convertedMillis = item; - if (gmttimezone.indexOf("GMT+") != -1) { - var offset = gmttimezone.substr(4, 1); - convertedMillis = new Date(item).getTime() + offset * 60 * 60000 + localOffset * 60000; - } - else if (gmttimezone.indexOf("GMT-") != -1) { - var offset = gmttimezone.substr(4, 1); - convertedMillis = new Date(item).getTime() - offset * 60 * 60000 + localOffset * 60000; - } - else { - // return PST by default - timezone = "PST"; - convertedMillis = new Date(item).getTime() - 8 * 60 * 60000 + localOffset * 60000; + var time = ""; + if(timezone.indexOf("GMT")!=-1){ + var zone = timezone; + var offset = parseInt(timezone.substr(3, 2)); + time = moment(item).utc().zone(-offset).format("YYYY-MM-DD HH:mm:ss ") + zone; + }else if(moment.tz.zone(timezone) != null){ + time = moment(item).tz(timezone).format(format); + }else{ + time = moment(item).utc().format(format); } - return $filter('date')(convertedMillis, format) + " " + timezone; - + return time; } }).filter('reverseToGMT0', function ($filter) { //backend store GMT+0 timezone ,by default front will show local,so convert to GMT+0 Date String format diff --git a/webapp/app/js/services/kylinProperties.js b/webapp/app/js/services/kylinProperties.js index dc9b94d38..6297696a0 100644 --- a/webapp/app/js/services/kylinProperties.js +++ b/webapp/app/js/services/kylinProperties.js @@ -31,6 +31,9 @@ KylinApp.service('kylinConfig', function (AdminService, $log) { }; this.getProperty = function (name) { + if(angular.isUndefined(_config)){ + return ''; + } var keyIndex = _config.indexOf('\n' + name + '='); var keyLength = name.length; var partialResult = _config.substr(keyIndex); diff --git a/webapp/app/partials/query/query.html b/webapp/app/partials/query/query.html index 30a21c357..841048eb6 100644 --- a/webapp/app/partials/query/query.html +++ b/webapp/app/partials/query/query.html @@ -145,7 +145,7 @@ - Queried At: {{query.savedAt}} in Project: {{query.project}} + Queried At: {{query.savedAt | utcToConfigTimeZone}} in Project: {{query.project}}