Fix date format and add util class
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
30
src/util.ts
Normal file
30
src/util.ts
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||||
import { History, HistoryStatus } from "../../act";
|
import { History, HistoryStatus } from "../../act";
|
||||||
|
import { Util } from "../../util";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
|
|
||||||
export default class HistoryTreeItem extends TreeItem implements 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;
|
let totalDuration: string | undefined;
|
||||||
if (history.date) {
|
if (history.date) {
|
||||||
const start = new Date(history.date.start).getTime();
|
totalDuration = `${Util.getTimeDuration(history.date.start, history.date.end)}s`;
|
||||||
const end = new Date(history.date.end).getTime();
|
|
||||||
totalDuration = `${((end - start) / 1000).toFixed(0).toString()}s`;
|
|
||||||
this.description = totalDuration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.description = totalDuration;
|
||||||
this.contextValue = `${HistoryTreeItem.contextValue}_${history.status}`;
|
this.contextValue = `${HistoryTreeItem.contextValue}_${history.status}`;
|
||||||
switch (history.status) {
|
switch (history.status) {
|
||||||
case HistoryStatus.Running:
|
case HistoryStatus.Running:
|
||||||
@@ -35,8 +34,8 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
|
|||||||
}
|
}
|
||||||
this.tooltip = `Name: ${history.name}\n` +
|
this.tooltip = `Name: ${history.name}\n` +
|
||||||
`Status: ${history.status}\n` +
|
`Status: ${history.status}\n` +
|
||||||
`Started: ${history.date ? history.date.start : 'N/A'}\n` +
|
`Started: ${history.date ? Util.getDateString(history.date.start) : 'N/A'}\n` +
|
||||||
`Ended: ${history.date ? history.date.end : 'N/A'}\n` +
|
`Ended: ${history.date ? Util.getDateString(history.date.end) : 'N/A'}\n` +
|
||||||
(totalDuration ? `Total Duration: ${totalDuration}\n` : ``);
|
(totalDuration ? `Total Duration: ${totalDuration}\n` : ``);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user