From 9d195f0f3197f568ee2838082ecbc874aa11e696 Mon Sep 17 00:00:00 2001 From: Spencer Date: Fri, 20 Feb 2026 05:16:11 +0000 Subject: [PATCH] refactor: address gemini-code-assist feedback on quota display - Simplifies conditional rendering logic in QuotaStatsInfo. - Improves chronological sorting of reset times in Config using Date objects. - Documents the Unix timestamp parsing heuristic in formatResetTime. - Streamlines intermediate string assignments in the formatter. --- packages/cli/src/ui/components/QuotaStatsInfo.tsx | 13 ++----------- packages/cli/src/ui/utils/formatters.ts | 3 ++- packages/core/src/config/config.ts | 4 +++- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/ui/components/QuotaStatsInfo.tsx b/packages/cli/src/ui/components/QuotaStatsInfo.tsx index 9d9a890a65..905a9ab9d2 100644 --- a/packages/cli/src/ui/components/QuotaStatsInfo.tsx +++ b/packages/cli/src/ui/components/QuotaStatsInfo.tsx @@ -57,18 +57,9 @@ export const QuotaStatsInfo: React.FC = ({ ? `Limit reached` : percentage !== undefined ? `${percentage.toFixed(0)}%` - : remaining !== undefined && remaining !== null - ? `${remaining.toLocaleString()}` - : 'Limit reached'} + : 'Limit reached'} - {remaining !== 0 && ( - - {percentage !== undefined || - (remaining !== undefined && remaining !== null) - ? ' usage remaining' - : ''} - - )} + {remaining !== 0 && usage remaining} {resetTime && `, ${(function (t) { const formatted = formatResetTime(t); diff --git a/packages/cli/src/ui/utils/formatters.ts b/packages/cli/src/ui/utils/formatters.ts index 1cdd30a37f..d68fccdf7b 100644 --- a/packages/cli/src/ui/utils/formatters.ts +++ b/packages/cli/src/ui/utils/formatters.ts @@ -105,7 +105,8 @@ export const formatResetTime = (resetTime: string): string => { if (isNaN(date.getTime())) { const timestamp = parseInt(resetTime, 10); if (!isNaN(timestamp)) { - // Could be seconds or milliseconds. If < 10^12, likely seconds. + // Heuristic: If the timestamp is less than 10^12, it is likely in seconds + // (as 10^12 ms is year 2001, while 10^12 s is far in the future). date = new Date(timestamp < 10000000000 ? timestamp * 1000 : timestamp); } } diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 9cd8fb9521..2d9225b5d0 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -1338,7 +1338,9 @@ export class Config { // For reset time, take the one that is nearest in the future (soonest reset) const resetTime = [proQuota?.resetTime, flashQuota?.resetTime] .filter((t): t is string => !!t) - .sort()[0]; + .map((t) => new Date(t)) + .sort((a, b) => a.getTime() - b.getTime())[0] + ?.toISOString(); return { remaining: (proQuota?.remaining ?? 0) + (flashQuota?.remaining ?? 0),