mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-08-09 16:36:40 -07:00
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.
This commit is contained in:
@@ -57,18 +57,9 @@ export const QuotaStatsInfo: React.FC<QuotaStatsInfoProps> = ({
|
||||
? `Limit reached`
|
||||
: percentage !== undefined
|
||||
? `${percentage.toFixed(0)}%`
|
||||
: remaining !== undefined && remaining !== null
|
||||
? `${remaining.toLocaleString()}`
|
||||
: 'Limit reached'}
|
||||
: 'Limit reached'}
|
||||
</Text>
|
||||
{remaining !== 0 && (
|
||||
<Text>
|
||||
{percentage !== undefined ||
|
||||
(remaining !== undefined && remaining !== null)
|
||||
? ' usage remaining'
|
||||
: ''}
|
||||
</Text>
|
||||
)}
|
||||
{remaining !== 0 && <Text> usage remaining</Text>}
|
||||
{resetTime &&
|
||||
`, ${(function (t) {
|
||||
const formatted = formatResetTime(t);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user