Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also add local version of short date time format #1211

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions skyvern-frontend/src/routes/workflows/WorkflowRun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { apiBaseUrl, envCredential } from "@/util/env";
import {
basicLocalTimeFormat,
basicTimeFormat,
localTimeFormatWithShortDate,
timeFormatWithShortDate,
} from "@/util/timeFormat";
import { cn } from "@/util/utils";
Expand Down Expand Up @@ -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">
Expand Down
29 changes: 28 additions & 1 deletion skyvern-frontend/src/util/timeFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localTimeFormatWithShortDate is a duplicate of basicLocalTimeFormat with a different date format. Consider extending basicLocalTimeFormat to support multiple date formats.

// 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}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider appending the local timezone abbreviation to the formatted string to clarify the timezone context.

Suggested change
return `${dateString} at ${timeString}`;
return `${dateString} at ${timeString} ${Intl.DateTimeFormat().resolvedOptions().timeZone}`;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider appending 'UTC' to the return string for consistency with other time format functions.

Suggested change
return `${dateString} at ${timeString}`;
return `${dateString} at ${timeString} UTC`;

}

export { basicLocalTimeFormat, basicTimeFormat, timeFormatWithShortDate };
export {
basicLocalTimeFormat,
basicTimeFormat,
timeFormatWithShortDate,
localTimeFormatWithShortDate,
};
Loading