From 2b131641da0d18437d8e4e4f130b16c09cc9cf40 Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Thu, 17 Oct 2024 23:32:15 -0400 Subject: [PATCH] Update date time format to include minutes and seconds Signed-off-by: Sanjula Ganepola --- src/dateUtils.ts | 14 ++++++++++++-- src/views/history/history.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/dateUtils.ts b/src/dateUtils.ts index 3285a95..b3a9ee6 100644 --- a/src/dateUtils.ts +++ b/src/dateUtils.ts @@ -20,11 +20,21 @@ export namespace DateUtils { } /** - * Get time duration in seconds. + * Get time duration in minutes and seconds. + * + * Examples: 31s or 2m 52s */ export function getTimeDuration(startValue: string, endValue: string) { const start = new Date(startValue).getTime(); const end = new Date(endValue).getTime(); - return ((end - start) / 1000).toFixed(0).toString(); + + const totalSeconds = Math.floor((end - start) / 1000); + if (totalSeconds < 60) { + return `${totalSeconds}s`; + } + + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + return `${minutes}m ${seconds}s`; } } \ No newline at end of file diff --git a/src/views/history/history.ts b/src/views/history/history.ts index b5d0729..7bacc8d 100644 --- a/src/views/history/history.ts +++ b/src/views/history/history.ts @@ -13,7 +13,7 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi let totalDuration: string | undefined; if (history.date) { - totalDuration = `${DateUtils.getTimeDuration(history.date.start, history.date.end)}s`; + totalDuration = DateUtils.getTimeDuration(history.date.start, history.date.end); } this.description = totalDuration;