From 02b9169589562a9570c6e1edf335b0be6830c2c7 Mon Sep 17 00:00:00 2001 From: Qinzheng Sun Date: Fri, 29 Mar 2019 11:50:32 +0800 Subject: [PATCH] [Web Portal] fix job detail's duration display (#2436) * fix * 231 * 706 --- .../job/job-view/fabric/job-detail/util.js | 19 ++++-- .../src/app/job/job-view/fabric/util.js | 66 ------------------- 2 files changed, 14 insertions(+), 71 deletions(-) delete mode 100644 src/webportal/src/app/job/job-view/fabric/util.js diff --git a/src/webportal/src/app/job/job-view/fabric/job-detail/util.js b/src/webportal/src/app/job/job-view/fabric/job-detail/util.js index 0cdf21bfac..4131f2d62c 100644 --- a/src/webportal/src/app/job/job-view/fabric/job-detail/util.js +++ b/src/webportal/src/app/job/job-view/fabric/job-detail/util.js @@ -47,10 +47,19 @@ export function getHumanizedJobStateString(jobInfo) { } export function getDurationString(jobInfo) { - const dt0 = jobInfo.jobStatus.createdTime && DateTime.fromMillis(jobInfo.jobStatus.createdTime); - const dt1 = jobInfo.jobStatus.completedTime && DateTime.fromMillis(jobInfo.jobStatus.completedTime); - if (dt0 && dt1) { - return Interval.fromDateTimes(dt0, dt1).toDuration(['hours', 'minutes', 'seconds']).toFormat('h:mm:ss'); + const start = jobInfo.jobStatus.createdTime && DateTime.fromMillis(jobInfo.jobStatus.createdTime); + const end = jobInfo.jobStatus.completedTime && DateTime.fromMillis(jobInfo.jobStatus.completedTime); + if (start) { + const dur = Interval.fromDateTimes(start, end || DateTime.utc()).toDuration(['days', 'hours', 'minutes', 'seconds']); + if (dur.days > 0) { + return dur.toFormat(`d'd' h'h' m'm' s's'`); + } else if (dur.hours > 0) { + return dur.toFormat(`h'h' m'm' s's'`); + } else if (dur.minutes > 0) { + return dur.toFormat(`m'm' s's'`); + } else { + return dur.toFormat(`s's'`); + } } else { return 'N/A'; } @@ -58,7 +67,7 @@ export function getDurationString(jobInfo) { export function printDateTime(dt) { - if (dt > DateTime.local().minus({week: 1}) && dt < DateTime.local().minus({minute: 1})) { + if (dt > DateTime.utc().minus({week: 1}) && dt < DateTime.utc().minus({minute: 1})) { return `${dt.toRelative()}, ${dt.toLocaleString(DateTime.TIME_24_SIMPLE)}`; } else { return dt.toLocaleString(DateTime.DATETIME_MED); diff --git a/src/webportal/src/app/job/job-view/fabric/util.js b/src/webportal/src/app/job/job-view/fabric/util.js deleted file mode 100644 index 2afd63bd4f..0000000000 --- a/src/webportal/src/app/job/job-view/fabric/util.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and -// to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -import {DateTime, Interval} from 'luxon'; - -export function getHumanizedJobStateString(jobInfo) { - const status = jobInfo.jobStatus; - let hjss = ''; - if (status.state === 'JOB_NOT_FOUND') { - hjss = 'N/A'; - } else if (status.state === 'WAITING') { - if (status.executionType === 'STOP') { - hjss = 'Stopping'; - } else { - hjss = 'Waiting'; - } - } else if (status.state === 'RUNNING') { - if (status.executionType === 'STOP') { - hjss = 'Stopping'; - } else { - hjss = 'Running'; - } - } else if (status.state === 'SUCCEEDED') { - hjss = 'Succeeded'; - } else if (status.state === 'FAILED') { - hjss = 'Failed'; - } else if (status.state === 'STOPPED') { - hjss = 'Stopped'; - } else { - hjss = 'Unknown'; - } - return hjss; -} - -export function getDurationString(jobInfo) { - const dt0 = DateTime.fromMillis(jobInfo.jobStatus.createdTime); - const dt1 = DateTime.fromMillis(jobInfo.jobStatus.completedTime); - if (dt0 && dt1) { - return Interval.fromDateTimes(dt0, dt1).toDuration(['hours', 'minutes', 'seconds']).toFormat('h:mm:ss'); - } else { - return 'N/A'; - } -} - - -export function printDateTime(dt) { - if (dt > DateTime.local().minus({week: 1})) { - return `${dt.toRelative()}, ${dt.toLocaleString(DateTime.TIME_24_SIMPLE)}`; - } else { - return dt.toLocaleString(DateTime.DATETIME_MED); - } -}