Optimizations + minor cleanups
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m15s
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m15s
This commit is contained in:
@@ -92,29 +92,25 @@ export async function fetchGiteaInfoFromUrl(
|
||||
return fetchGiteaRepoInfo(config);
|
||||
}
|
||||
|
||||
const MINUTE_MS = 60_000;
|
||||
const HOUR_MS = 3_600_000;
|
||||
const DAY_MS = 86_400_000;
|
||||
|
||||
const pluralize = (n: number, unit: string) => `${n} ${unit}${n !== 1 ? "s" : ""} ago`;
|
||||
|
||||
export function formatRelativeTime(dateString: string): string {
|
||||
if (!dateString) return "Unknown";
|
||||
|
||||
const date = new Date(dateString);
|
||||
const now = new Date();
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
|
||||
const diffMinutes = Math.floor(diffMs / (1000 * 60));
|
||||
const diffMs = Date.now() - new Date(dateString).getTime();
|
||||
const diffMinutes = Math.floor(diffMs / MINUTE_MS);
|
||||
const diffHours = Math.floor(diffMs / HOUR_MS);
|
||||
const diffDays = Math.floor(diffMs / DAY_MS);
|
||||
|
||||
if (diffMinutes < 60) {
|
||||
return `${diffMinutes} minute${diffMinutes !== 1 ? "s" : ""} ago`;
|
||||
} else if (diffHours < 24) {
|
||||
return `${diffHours} hour${diffHours !== 1 ? "s" : ""} ago`;
|
||||
} else if (diffDays < 30) {
|
||||
return `${diffDays} day${diffDays !== 1 ? "s" : ""} ago`;
|
||||
} else if (diffDays < 365) {
|
||||
const months = Math.floor(diffDays / 30);
|
||||
return `${months} month${months !== 1 ? "s" : ""} ago`;
|
||||
} else {
|
||||
const years = Math.floor(diffDays / 365);
|
||||
return `${years} year${years !== 1 ? "s" : ""} ago`;
|
||||
}
|
||||
if (diffMinutes < 60) return pluralize(diffMinutes, "minute");
|
||||
if (diffHours < 24) return pluralize(diffHours, "hour");
|
||||
if (diffDays < 30) return pluralize(diffDays, "day");
|
||||
if (diffDays < 365) return pluralize(Math.floor(diffDays / 30), "month");
|
||||
return pluralize(Math.floor(diffDays / 365), "year");
|
||||
}
|
||||
|
||||
export function formatRepoSize(sizeKb: number): string {
|
||||
|
||||
Reference in New Issue
Block a user