Skip to content

Commit

Permalink
[SPARK-16986][WEB-UI] Converter Started, Completed and Last Updated t…
Browse files Browse the repository at this point in the history
…o 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 <wgyumg@gmail.com>

Closes #19640 from wangyum/SPARK-16986.
  • Loading branch information
wangyum authored and Marcelo Vanzin committed Dec 12, 2017
1 parent bc8933f commit d500773
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"];
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/resources/org/apache/spark/ui/static/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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> ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d500773

Please sign in to comment.