Also add local version of short date time format (#1211)

This commit is contained in:
Shuchang Zheng
2024-11-18 06:04:16 -08:00
committed by GitHub
parent 5e253c82aa
commit 7120ef42a0
2 changed files with 35 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ import { apiBaseUrl, envCredential } from "@/util/env";
import {
basicLocalTimeFormat,
basicTimeFormat,
localTimeFormatWithShortDate,
timeFormatWithShortDate,
} from "@/util/timeFormat";
import { cn } from "@/util/utils";
@@ -475,10 +476,14 @@ function WorkflowRun() {
<Label className="text-sm text-slate-400">Created</Label>
<span
className="truncate text-sm"
title={basicLocalTimeFormat(currentRunningTask.created_at)}
title={timeFormatWithShortDate(
currentRunningTask.created_at,
)}
>
{currentRunningTask &&
timeFormatWithShortDate(currentRunningTask.created_at)}
localTimeFormatWithShortDate(
currentRunningTask.created_at,
)}
</span>
</div>
<div className="mt-auto flex justify-end">

View File

@@ -42,7 +42,34 @@ function timeFormatWithShortDate(time: string): string {
const dateString =
date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear();
const timeString = date.toLocaleTimeString("en-US");
return `${dateString} at ${timeString} UTC`;
}
function localTimeFormatWithShortDate(time: string): string {
// Adjust the fractional seconds to milliseconds (3 digits)
time = time.replace(/\.(\d{3})\d*/, ".$1");
// Append 'Z' to indicate UTC time if not already present
if (!time.endsWith("Z")) {
time += "Z";
}
const date = new Date(time);
const localTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const dateString =
date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear();
const timeString = date.toLocaleTimeString("en-US", {
timeZone: localTimezone,
});
return `${dateString} at ${timeString}`;
}
export { basicLocalTimeFormat, basicTimeFormat, timeFormatWithShortDate };
export {
basicLocalTimeFormat,
basicTimeFormat,
timeFormatWithShortDate,
localTimeFormatWithShortDate,
};