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 55d540d8317a..4cfe46ec914a 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()); }); 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 aa7e86037255..2cde66b081a1 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"]; 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 edc0ee2ce181..4f63f6413d6d 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]; + } +} 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 6399dccc1676..946344dcf27a 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 @@ -55,6 +55,10 @@ private[history] class HistoryPage(parent: HistoryServer) extends WebUIPage("") } } + { +
Client local time zone:
+ } + { if (allAppsSize > 0) { ++ 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 c11543a4b3ba..cf2077038cd9 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 @@ -352,7 +352,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)