mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 20:51:17 +00:00
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import type { TaskStatus } from "@/modules/shared/schemas/info";
|
|
|
|
const TIME_ZONE = "Europe/Berlin";
|
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
|
|
// Server läuft in UTC; "heute" soll aber der Kalendertag in Deutschland sein.
|
|
export function berlinToday() {
|
|
return new Intl.DateTimeFormat("en-CA", { timeZone: TIME_ZONE }).format(new Date());
|
|
}
|
|
|
|
function daysBetween(fromIso: string, toIso: string) {
|
|
return Math.round((Date.parse(toIso) - Date.parse(fromIso)) / DAY_MS);
|
|
}
|
|
|
|
const shortDate = new Intl.DateTimeFormat("de-DE", { day: "numeric", month: "short", timeZone: "UTC" });
|
|
|
|
export function formatTaskTiming(status: TaskStatus, since: string, today = berlinToday()) {
|
|
const days = daysBetween(since, today);
|
|
|
|
if (status === "planned" || days < 0) {
|
|
return `ab ${shortDate.format(new Date(`${since}T00:00:00Z`))}`;
|
|
}
|
|
if (days === 0) return "seit heute";
|
|
if (days === 1) return "seit gestern";
|
|
return `seit ${days} Tagen`;
|
|
}
|
|
|
|
const dateTime = new Intl.DateTimeFormat("de-DE", {
|
|
day: "2-digit",
|
|
month: "2-digit",
|
|
year: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
timeZone: TIME_ZONE,
|
|
});
|
|
|
|
export function formatDateTime(timestamp: string) {
|
|
return `${dateTime.format(new Date(timestamp))} Uhr`;
|
|
}
|
|
|
|
const percent = new Intl.NumberFormat("de-DE", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
|
|
export function formatUptime(value: number) {
|
|
return `${percent.format(value)} %`;
|
|
}
|