diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..0e3e03c --- /dev/null +++ b/src/util.ts @@ -0,0 +1,30 @@ +export namespace Util { + /** + * Get date time string. + * + * Example: Oct 17, 2024, 11:26:47 PM EDT + */ + export function getDateString(value?: string) { + const date = value ? new Date(value) : new Date(); + + return date.toLocaleString(undefined, { + year: 'numeric', + month: 'short', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: "numeric", + hour12: true, + timeZoneName: 'short' + }); + } + + /** + * Get time duration in seconds. + */ + 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(); + } +} \ No newline at end of file diff --git a/src/views/history/history.ts b/src/views/history/history.ts index b25f2a7..dac281a 100644 --- a/src/views/history/history.ts +++ b/src/views/history/history.ts @@ -1,5 +1,6 @@ import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { History, HistoryStatus } from "../../act"; +import { Util } from "../../util"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; export default class HistoryTreeItem extends TreeItem implements GithubLocalActionsTreeItem { @@ -12,12 +13,10 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi let totalDuration: string | undefined; if (history.date) { - const start = new Date(history.date.start).getTime(); - const end = new Date(history.date.end).getTime(); - totalDuration = `${((end - start) / 1000).toFixed(0).toString()}s`; - this.description = totalDuration; + totalDuration = `${Util.getTimeDuration(history.date.start, history.date.end)}s`; } + this.description = totalDuration; this.contextValue = `${HistoryTreeItem.contextValue}_${history.status}`; switch (history.status) { case HistoryStatus.Running: @@ -35,8 +34,8 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi } this.tooltip = `Name: ${history.name}\n` + `Status: ${history.status}\n` + - `Started: ${history.date ? history.date.start : 'N/A'}\n` + - `Ended: ${history.date ? history.date.end : 'N/A'}\n` + + `Started: ${history.date ? Util.getDateString(history.date.start) : 'N/A'}\n` + + `Ended: ${history.date ? Util.getDateString(history.date.end) : 'N/A'}\n` + (totalDuration ? `Total Duration: ${totalDuration}\n` : ``); }