fix(cli): refine quota reset time formatting and call sites

- Reverts formatResetTime to return only the raw duration string.
- Moves 'resets in' prefix logic to call sites to prevent duplication.
- Fixes double parentheses in StatsDisplay for imminent resets.
- Removes brittle string replacement in favor of direct formatting.
This commit is contained in:
Spencer
2026-02-20 05:11:11 +00:00
parent 2ecdc4b533
commit 211a6fb50a
4 changed files with 29 additions and 14 deletions
@@ -42,7 +42,16 @@ export const QuotaDisplay: React.FC<QuotaDisplayProps> = ({
});
const resetInfo =
!terse && resetTime ? `, ${formatResetTime(resetTime)}` : '';
!terse && resetTime
? (function (t) {
const formatted = formatResetTime(t);
const info =
formatted === 'Resetting...' || formatted === '< 1m'
? formatted
: `resets in ${formatted}`;
return `, ${info}`;
})(resetTime)
: '';
if (remaining === 0) {
return (
@@ -69,7 +69,13 @@ export const QuotaStatsInfo: React.FC<QuotaStatsInfoProps> = ({
: ''}
</Text>
)}
{resetTime && `, ${formatResetTime(resetTime)}`}
{resetTime &&
`, ${(function (t) {
const formatted = formatResetTime(t);
return formatted === 'Resetting...' || formatted === '< 1m'
? formatted
: `resets in ${formatted}`;
})(resetTime)}`}
</Text>
)}
{showDetails && (
@@ -365,10 +365,13 @@ const ModelUsageTable: React.FC<{
<Text color={theme.text.secondary}>
{' '}
(
{formatResetTime(row.bucket.resetTime).replace(
'resets in',
'Resets in',
)}
{(function (t) {
const formatted = formatResetTime(t);
return formatted === 'Resetting...' ||
formatted === '< 1m'
? formatted
: `Resets in ${formatted}`;
})(row.bucket.resetTime)}
)
</Text>
)}
+5 -8
View File
@@ -115,7 +115,7 @@ export const formatResetTime = (resetTime: string): string => {
}
const diff = date.getTime() - Date.now();
if (diff <= 0) return '(Resetting...)';
if (diff <= 0) return 'Resetting...';
const totalMinutes = Math.ceil(diff / (1000 * 60));
const hours = Math.floor(totalMinutes / 60);
@@ -128,16 +128,13 @@ export const formatResetTime = (resetTime: string): string => {
unitDisplay: 'narrow',
}).format(val);
let timeStr = '';
if (hours > 0 && minutes > 0) {
timeStr = `${fmt(hours, 'hour')} ${fmt(minutes, 'minute')}`;
return `${fmt(hours, 'hour')} ${fmt(minutes, 'minute')}`;
} else if (hours > 0) {
timeStr = fmt(hours, 'hour');
return fmt(hours, 'hour');
} else if (minutes > 0) {
timeStr = fmt(minutes, 'minute');
return fmt(minutes, 'minute');
} else {
timeStr = '< 1m';
return '< 1m';
}
return `resets in ${timeStr}`;
};