mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-13 10:49:21 +00:00
27 lines
735 B
TypeScript
27 lines
735 B
TypeScript
export function getErrorMessage(error: unknown): string {
|
|
if (error instanceof Error) {
|
|
return error.message;
|
|
}
|
|
if (typeof error === "string") {
|
|
return error;
|
|
}
|
|
return String(error);
|
|
}
|
|
export function getAge(timestamp: Date | string | undefined): string {
|
|
if (!timestamp) return "unknown";
|
|
|
|
const now = new Date();
|
|
const created = new Date(timestamp);
|
|
const diff = now.getTime() - created.getTime();
|
|
|
|
const seconds = Math.floor(diff / 1000);
|
|
const minutes = Math.floor(seconds / 60);
|
|
const hours = Math.floor(minutes / 60);
|
|
const days = Math.floor(hours / 24);
|
|
|
|
if (days > 0) return `${days}d`;
|
|
if (hours > 0) return `${hours}h`;
|
|
if (minutes > 0) return `${minutes}m`;
|
|
return `${seconds}s`;
|
|
}
|