fix: show quota reset times in local timezone (#1128)

Formats rate-limit reset timestamps in the client timezone
Keeps server-provided reset labels as fallbacks
Applies consistent reset labels across header, usage, and VS Code views
This commit is contained in:
Bohdan Triapitsyn
2026-05-15 01:03:36 +03:00
parent 7b8861144e
commit 29811ec03e
5 changed files with 48 additions and 9 deletions
+1
View File
@@ -4,6 +4,7 @@ export {
clampPercent,
formatPercent,
formatQuotaValueLabel,
formatQuotaResetLabel,
resolveUsageTone,
formatWindowLabel,
calculatePace,
+36
View File
@@ -19,6 +19,42 @@ export const formatQuotaValueLabel = (
return valueLabel ?? formatPercent(percent);
};
export const formatQuotaResetLabel = (
resetAt: number | null,
fallback?: string | null,
): string => {
if (!resetAt) {
return fallback ?? '';
}
try {
const resetDate = new Date(resetAt);
if (!Number.isFinite(resetDate.getTime())) {
return fallback ?? '';
}
const now = new Date();
const isToday = resetDate.toDateString() === now.toDateString();
if (isToday) {
return resetDate.toLocaleTimeString(undefined, {
hour: 'numeric',
minute: '2-digit',
});
}
return resetDate.toLocaleString(undefined, {
month: 'short',
day: 'numeric',
weekday: 'short',
hour: 'numeric',
minute: '2-digit',
});
} catch {
return fallback ?? '';
}
};
export const resolveUsageTone = (percent: number | null): 'safe' | 'warn' | 'critical' => {
if (percent === null) {
return 'safe';