This commit is contained in:
yoan
2024-08-21 12:19:12 +08:00
commit 50fa238d88
89 changed files with 11835 additions and 0 deletions

15
ui/src/lib/error.ts Normal file
View File

@@ -0,0 +1,15 @@
export const getErrMessage = (error: unknown): string => {
if (error instanceof Error) {
return error.message;
} else if (
typeof error === "object" &&
error !== null &&
"message" in error
) {
return String(error.message);
} else if (typeof error === "string") {
return error;
} else {
return "Something went wrong";
}
};

22
ui/src/lib/time.ts Normal file
View File

@@ -0,0 +1,22 @@
export const convertZulu2Beijing = (zuluTime: string) => {
const utcDate = new Date(zuluTime);
// Format the Beijing time
const formattedBeijingTime = new Intl.DateTimeFormat("zh-CN", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
timeZone: "Asia/Shanghai",
}).format(utcDate);
return formattedBeijingTime;
};
export const getDate = (zuluTime: string) => {
const time = convertZulu2Beijing(zuluTime);
return time.split(" ")[0];
};

6
ui/src/lib/utils.ts Normal file
View File

@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}