Update date time format to include minutes and seconds

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-10-17 23:32:15 -04:00
parent 7b29d507b2
commit 2b131641da
2 changed files with 13 additions and 3 deletions

View File

@@ -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`;
}
}

View File

@@ -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;