Files
codexbar-mobile/lib/timeUtils.ts
T
space ba7d957155
CodexBar Mobile Build / build-android (push) Failing after 1m38s
CodexBar Mobile Build / release (push) Has been skipped
Maximus upgradus
2026-06-24 20:16:34 +02:00

36 lines
1.3 KiB
TypeScript

export function formatResetCountdown(resetAtSeconds: number): string {
const nowSeconds = Math.floor(Date.now() / 1000);
const diffSeconds = resetAtSeconds - nowSeconds;
if (diffSeconds <= 0) return "resetting now";
if (diffSeconds < 60) return "resets in <1m";
const totalHours = Math.floor(diffSeconds / 3600);
const minutes = Math.floor((diffSeconds % 3600) / 60);
if (totalHours >= 24) {
const days = Math.floor(totalHours / 24);
const hours = totalHours % 24;
if (hours > 0) return `resets in ${days}d ${hours}h`;
return `resets in ${days}d`;
}
if (totalHours > 0 && minutes > 0) return `resets in ${totalHours}h ${minutes}m`;
if (totalHours > 0) return `resets in ${totalHours}h`;
return `resets in ${minutes}m`;
}
export function formatResetCountdownISO(isoString: string): string {
const resetAtSeconds = Math.floor(new Date(isoString).getTime() / 1000);
return formatResetCountdown(resetAtSeconds);
}
export function windowLabel(limitWindowSeconds: number): string {
const hours = limitWindowSeconds / 3600;
if (hours < 24) return `${Math.round(hours)}h`;
const days = hours / 24;
const wholeDays = Math.floor(days);
const remainderHours = Math.round(hours - wholeDays * 24);
if (remainderHours === 0) return `${wholeDays}d`;
return `${wholeDays}d ${remainderHours}h`;
}