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:
@@ -4,6 +4,7 @@ export {
|
||||
clampPercent,
|
||||
formatPercent,
|
||||
formatQuotaValueLabel,
|
||||
formatQuotaResetLabel,
|
||||
resolveUsageTone,
|
||||
formatWindowLabel,
|
||||
calculatePace,
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user