Browse Source

YARN-7750. [UI2] Render time related fields in all pages to the browser timezone. Contributed by Vasudevan Skm.

Sunil G 7 years ago
parent
commit
8e5472b1e6

+ 3 - 4
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/utils/converter.js

@@ -17,6 +17,7 @@
  */
  */
 
 
 import Constants from 'yarn-ui/constants';
 import Constants from 'yarn-ui/constants';
+import { convertTimestampWithTz } from "./date-utils";
 
 
 export default {
 export default {
   containerIdToAttemptId: function(containerId) {
   containerIdToAttemptId: function(containerId) {
@@ -82,12 +83,10 @@ export default {
     return total * 1000;
     return total * 1000;
   },
   },
   timeStampToDate: function(timeStamp) {
   timeStampToDate: function(timeStamp) {
-    var dateTimeString = moment(parseInt(timeStamp)).format("YYYY/MM/DD HH:mm:ss");
-    return dateTimeString;
+    return convertTimestampWithTz(timeStamp, "YYYY/MM/DD HH:mm:ss");
   },
   },
   timeStampToDateOnly: function(timeStamp) {
   timeStampToDateOnly: function(timeStamp) {
-    var dateTimeString = moment(parseInt(timeStamp)).format("YYYY/MM/DD");
-    return dateTimeString;
+    return convertTimestampWithTz(timeStamp, "YYYY/MM/DD");
   },
   },
   dateToTimeStamp: function(date) {
   dateToTimeStamp: function(date) {
     if (date) {
     if (date) {

+ 27 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/utils/date-utils.js

@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+const defaultTz = "America/Los_Angeles";
+
+const getDefaultTimezone = () => {
+  return moment.tz.guess() || defaultTz;
+};
+
+export const convertTimestampWithTz = (timestamp, format = "YYYY/MM/DD") =>
+  moment.tz(timestamp, getDefaultTimezone()).format(format);

+ 1 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/ember-cli-build.js

@@ -42,6 +42,7 @@ module.exports = function(defaults) {
   app.import("bower_components/datatables/media/css/jquery.dataTables.min.css");
   app.import("bower_components/datatables/media/css/jquery.dataTables.min.css");
   app.import("bower_components/datatables/media/js/jquery.dataTables.min.js");
   app.import("bower_components/datatables/media/js/jquery.dataTables.min.js");
   app.import("bower_components/momentjs/min/moment.min.js");
   app.import("bower_components/momentjs/min/moment.min.js");
+  app.import("bower_components/moment-timezone/builds/moment-timezone-with-data-2010-2020.min.js");
   app.import("bower_components/select2/dist/css/select2.min.css");
   app.import("bower_components/select2/dist/css/select2.min.css");
   app.import("bower_components/select2/dist/js/select2.min.js");
   app.import("bower_components/select2/dist/js/select2.min.js");
   app.import('bower_components/jquery-ui/jquery-ui.js');
   app.import('bower_components/jquery-ui/jquery-ui.js');