MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / formatResetTime

Function formatResetTime

packages/oauth/src/managed-usage.ts:144–158  ·  view source on GitHub ↗
(val: string)

Source from the content-addressed store, hash-verified

142}
143
144export function formatResetTime(val: string): string {
145 let normalised = val;
146 // ISO with nano precision → trim to ms for JS Date.
147 if (normalised.includes('.') && normalised.endsWith('Z')) {
148 const [base, frac] = normalised.slice(0, -1).split('.');
149 if (base !== undefined && frac !== undefined) {
150 normalised = `${base}.${frac.slice(0, 3)}Z`;
151 }
152 }
153 const parsed = Date.parse(normalised);
154 if (!Number.isFinite(parsed)) return `resets at ${val}`;
155 const diffSec = Math.floor((parsed - Date.now()) / 1000);
156 if (diffSec <= 0) return 'reset';
157 return `resets in ${formatDuration(diffSec)}`;
158}
159
160export function formatDuration(totalSeconds: number): string {
161 if (!Number.isFinite(totalSeconds) || totalSeconds <= 0) return '0s';

Callers 2

resetHintFromFunction · 0.85

Calls 2

formatDurationFunction · 0.70
nowMethod · 0.65

Tested by

no test coverage detected