Repository: spark
Updated Branches:
  refs/heads/master bc8933faf -> d5007734b


[SPARK-16986][WEB-UI] Converter Started, Completed and Last Updated to client 
time zone in history page

## What changes were proposed in this pull request?

This PR is converted the ` Started`, `Completed` and `Last Updated` to client 
local time in the history page.

## How was this patch tested?

Manual tests for Chrome, Firefox and Safari

#### Before modifying:
<img width="1280" alt="before-webui" 
src="https://user-images.githubusercontent.com/5399861/32315920-19de825c-bfe9-11e7-9db6-edbf57d50792.png";>

#### After modifying:
<img width="1160" alt="after" 
src="https://user-images.githubusercontent.com/5399861/32867988-fb9d9dec-caaa-11e7-85dd-3152ff0d9ef0.png";>

Author: Yuming Wang <wgy...@gmail.com>

Closes #19640 from wangyum/SPARK-16986.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/d5007734
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/d5007734
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/d5007734

Branch: refs/heads/master
Commit: d5007734b22fbee5eccb1682eef13479780423ab
Parents: bc8933f
Author: Yuming Wang <wgy...@gmail.com>
Authored: Tue Dec 12 10:07:18 2017 -0800
Committer: Marcelo Vanzin <van...@cloudera.com>
Committed: Tue Dec 12 10:07:18 2017 -0800

----------------------------------------------------------------------
 .../spark/ui/static/historypage-common.js       | 11 ++++----
 .../org/apache/spark/ui/static/historypage.js   | 11 +++-----
 .../org/apache/spark/ui/static/utils.js         | 28 ++++++++++++++++++++
 .../spark/deploy/history/HistoryPage.scala      |  4 +++
 .../deploy/history/HistoryServerSuite.scala     |  2 +-
 5 files changed, 42 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/d5007734/core/src/main/resources/org/apache/spark/ui/static/historypage-common.js
----------------------------------------------------------------------
diff --git 
a/core/src/main/resources/org/apache/spark/ui/static/historypage-common.js 
b/core/src/main/resources/org/apache/spark/ui/static/historypage-common.js
index 55d540d..4cfe46e 100644
--- a/core/src/main/resources/org/apache/spark/ui/static/historypage-common.js
+++ b/core/src/main/resources/org/apache/spark/ui/static/historypage-common.js
@@ -16,9 +16,10 @@
  */
 
 $(document).ready(function() {
-    if ($('#last-updated').length) {
-      var lastUpdatedMillis = Number($('#last-updated').text());
-      var updatedDate = new Date(lastUpdatedMillis);
-      $('#last-updated').text(updatedDate.toLocaleDateString()+", 
"+updatedDate.toLocaleTimeString())
-    }
+  if ($('#last-updated').length) {
+    var lastUpdatedMillis = Number($('#last-updated').text());
+    $('#last-updated').text(formatTimeMillis(lastUpdatedMillis));
+  }
+
+  $('#time-zone').text(getTimeZone());
 });

http://git-wip-us.apache.org/repos/asf/spark/blob/d5007734/core/src/main/resources/org/apache/spark/ui/static/historypage.js
----------------------------------------------------------------------
diff --git a/core/src/main/resources/org/apache/spark/ui/static/historypage.js 
b/core/src/main/resources/org/apache/spark/ui/static/historypage.js
index aa7e860..2cde66b 100644
--- a/core/src/main/resources/org/apache/spark/ui/static/historypage.js
+++ b/core/src/main/resources/org/apache/spark/ui/static/historypage.js
@@ -37,11 +37,6 @@ function makeIdNumeric(id) {
   return resl;
 }
 
-function formatDate(date) {
-  if (date <= 0) return "-";
-  else return date.split(".")[0].replace("T", " ");
-}
-
 function getParameterByName(name, searchString) {
   var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
   results = regex.exec(searchString);
@@ -129,9 +124,9 @@ $(document).ready(function() {
         var num = app["attempts"].length;
         for (j in app["attempts"]) {
           var attempt = app["attempts"][j];
-          attempt["startTime"] = formatDate(attempt["startTime"]);
-          attempt["endTime"] = formatDate(attempt["endTime"]);
-          attempt["lastUpdated"] = formatDate(attempt["lastUpdated"]);
+          attempt["startTime"] = formatTimeMillis(attempt["startTimeEpoch"]);
+          attempt["endTime"] = formatTimeMillis(attempt["endTimeEpoch"]);
+          attempt["lastUpdated"] = 
formatTimeMillis(attempt["lastUpdatedEpoch"]);
           attempt["log"] = uiRoot + "/api/v1/applications/" + id + "/" +
             (attempt.hasOwnProperty("attemptId") ? attempt["attemptId"] + "/" 
: "") + "logs";
           attempt["durationMillisec"] = attempt["duration"];

http://git-wip-us.apache.org/repos/asf/spark/blob/d5007734/core/src/main/resources/org/apache/spark/ui/static/utils.js
----------------------------------------------------------------------
diff --git a/core/src/main/resources/org/apache/spark/ui/static/utils.js 
b/core/src/main/resources/org/apache/spark/ui/static/utils.js
index edc0ee2..4f63f64 100644
--- a/core/src/main/resources/org/apache/spark/ui/static/utils.js
+++ b/core/src/main/resources/org/apache/spark/ui/static/utils.js
@@ -46,3 +46,31 @@ function formatBytes(bytes, type) {
     var i = Math.floor(Math.log(bytes) / Math.log(k));
     return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
 }
+
+function padZeroes(num) {
+  return ("0" + num).slice(-2);
+}
+
+function formatTimeMillis(timeMillis) {
+  if (timeMillis <= 0) {
+    return "-";
+  } else {
+    var dt = new Date(timeMillis);
+    return dt.getFullYear() + "-" +
+      padZeroes(dt.getMonth() + 1) + "-" +
+      padZeroes(dt.getDate()) + " " +
+      padZeroes(dt.getHours()) + ":" +
+      padZeroes(dt.getMinutes()) + ":" +
+      padZeroes(dt.getSeconds());
+  }
+}
+
+function getTimeZone() {
+  try {
+    return Intl.DateTimeFormat().resolvedOptions().timeZone;
+  } catch(ex) {
+    // Get time zone from a string representing the date,
+    // eg. "Thu Nov 16 2017 01:13:32 GMT+0800 (CST)" -> "CST"
+    return new Date().toString().match(/\((.*)\)/)[1];
+  }
+}

http://git-wip-us.apache.org/repos/asf/spark/blob/d5007734/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala
----------------------------------------------------------------------
diff --git 
a/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala 
b/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala
index d3dd589..5d62a7d 100644
--- a/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala
+++ b/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala
@@ -58,6 +58,10 @@ private[history] class HistoryPage(parent: HistoryServer) 
extends WebUIPage("")
             }
 
             {
+            <p>Client local time zone: <span id="time-zone"></span></p>
+            }
+
+            {
             if (allAppsSize > 0) {
               <script 
src={UIUtils.prependBaseUri("/static/dataTables.rowsGroup.js")}></script> ++
                 <div id="history-summary" class="row-fluid"></div> ++

http://git-wip-us.apache.org/repos/asf/spark/blob/d5007734/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala
----------------------------------------------------------------------
diff --git 
a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala 
b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala
index 4e4395d..3a9790c 100644
--- 
a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala
+++ 
b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala
@@ -345,7 +345,7 @@ class HistoryServerSuite extends SparkFunSuite with 
BeforeAndAfter with Matchers
         .map(_.get)
         .filter(_.startsWith(url)).toList
 
-      // there are atleast some URL links that were generated via javascript,
+      // there are at least some URL links that were generated via javascript,
       // and they all contain the spark.ui.proxyBase (uiRoot)
       links.length should be > 4
       all(links) should startWith(url + uiRoot)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to