From 165c948e3297fd5ebcee771fcbf7a0c20fccfaae Mon Sep 17 00:00:00 2001 From: TJX2014 Date: Tue, 30 Jun 2020 08:56:59 -0500 Subject: [PATCH] [SPARK-32068][WEBUI] Correct task lauchtime show issue due to timezone in stage tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What changes were proposed in this pull request? `formatDate` in utils.js `org/apache/spark/ui/static/utils.js` is partly refactored. ### Why are the changes needed? In branch-2.4,task launch time is returned as html string from driver, while in branch-3.x,this is returned in JSON Object as`Date`type from `org.apache.spark.status.api.v1.TaskData` Due to: LaunchTime from jersey server in spark driver is correct, which will be converted to date string like `2020-06-28T02:57:42.605GMT` in json object, then the formatDate in utils.js treat it as date.split(".")[0].replace("T", " "). So `2020-06-28T02:57:42.605GMT` will be converted to `2020-06-28 02:57:42`, but correct is `2020-06-28 10:57:42` in GMT+8 timezone. ![选区_071](https://user-images.githubusercontent.com/7149304/85937186-b6d36780-b933-11ea-8382-80a3891f1c2a.png) ![选区_070](https://user-images.githubusercontent.com/7149304/85937190-bcc94880-b933-11ea-8860-2083c97ea269.png) ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Manual test. Closes #28918 from TJX2014/master-SPARK-32068-ui-task-lauch-time-tz. Authored-by: TJX2014 Signed-off-by: Thomas Graves --- .../resources/org/apache/spark/ui/static/utils.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 6fc34a9e1f7ea..2e46111bf1ba0 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 @@ -56,13 +56,17 @@ function formatTimeMillis(timeMillis) { return "-"; } else { var dt = new Date(timeMillis); + return formatDateString(dt); + } +} + +function formatDateString(dt) { return dt.getFullYear() + "-" + padZeroes(dt.getMonth() + 1) + "-" + padZeroes(dt.getDate()) + " " + padZeroes(dt.getHours()) + ":" + padZeroes(dt.getMinutes()) + ":" + padZeroes(dt.getSeconds()); - } } function getTimeZone() { @@ -161,7 +165,10 @@ function setDataTableDefaults() { function formatDate(date) { if (date <= 0) return "-"; - else return date.split(".")[0].replace("T", " "); + else { + var dt = new Date(date.replace("GMT", "Z")) + return formatDateString(dt); + } } function createRESTEndPointForExecutorsPage(appId) {