Skip to content
19 changes: 14 additions & 5 deletions core/src/main/resources/org/apache/spark/ui/static/historypage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ function makeIdNumeric(id) {
}

function formatDate(date) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to utils.js

if (date <= 0) return "-";
else return date.split(".")[0].replace("T", " ");
if (date <= 0) {
return "-";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for curious, what does a single - mean here? invalid value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, invalid value. Maybe we can remove this.

} else {
var dt = new Date(date);
return dt.getFullYear() + "-" +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not familiar with js, does js have something like java SimpleDateFormat?

@wangyum wangyum Nov 13, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Native Javascript does not support:
https://www.w3schools.com/js/js_date_formats.asp

Use the momentjs library seems too heavy.

("0" + (dt.getMonth() + 1)).slice(-2) + "-" +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks a bit hacky, is there any way in js to print a number to 2 letters?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this:

function formatDate(date) {
  if (date <= 0) {
    return "-";
  } else {
    var dt = new Date(date);
    return dt.getFullYear() + "-" +
      (dt.getMonth() + 1).toString().padStart(2, "0") + "-" +
      (dt.getDate()).toString().padStart(2, "0") + " " +
      (dt.getHours()).toString().padStart(2, "0") + ":" +
      (dt.getMinutes()).toString().padStart(2, "0") + ":" +
      (dt.getSeconds()).toString().padStart(2, "0");
  }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea much better, .toString().padStart(2, "0") can be a method.

("0" + dt.getDate()).slice(-2) + " " +
("0" + dt.getHours()).slice(-2) + ":" +
("0" + dt.getMinutes()).slice(-2) + ":" +
("0" + dt.getSeconds()).slice(-2);
}
}

function getParameterByName(name, searchString) {
Expand Down Expand Up @@ -129,9 +138,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"] = formatDate(attempt["startTimeEpoch"]);
attempt["endTime"] = formatDate(attempt["endTimeEpoch"]);
attempt["lastUpdated"] = formatDate(attempt["lastUpdatedEpoch"]);
attempt["log"] = uiRoot + "/api/v1/applications/" + id + "/" +
(attempt.hasOwnProperty("attemptId") ? attempt["attemptId"] + "/" : "") + "logs";
attempt["durationMillisec"] = attempt["duration"];
Expand Down