Skip to content

Fix quota reset timestamp parsing for Unix seconds - #768

Merged
decolua merged 1 commit into
decolua:masterfrom
DEYLNN:fix-reset-time-unix-timestamps
Apr 28, 2026
Merged

decolua merged 1 commit into
decolua:masterfrom
DEYLNN:fix-reset-time-unix-timestamps

Conversation

@DEYLNN

@DEYLNN DEYLNN commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes quota reset timestamp parsing so provider APIs that return Unix timestamps in seconds, milliseconds, or numeric strings are handled correctly.

Why

Previously numeric reset values were always passed directly to new Date(...), which treats numbers as milliseconds. If a provider returns Unix seconds, the UI can display an incorrect 1970-era reset date.

Changes

  • Detect numeric Unix timestamps in seconds vs milliseconds.
  • Support numeric string timestamps the same way.
  • Preserve existing ISO/parseable string behavior.

Testing

Not run; small parsing-only change.

@decolua
decolua merged commit 85959aa into decolua:master Apr 28, 2026
luckystart79-lang pushed a commit to luckystart79-lang/minirouter that referenced this pull request May 2, 2026
Co-authored-by: Delynn Assistant <zhen@dkzhen.org>
caothu159 pushed a commit to diepxuan/9router that referenced this pull request May 14, 2026
Co-authored-by: Delynn Assistant <zhen@dkzhen.org>
diegosouzapw pushed a commit to cheaper-inference/OmniRoute that referenced this pull request Jun 21, 2026
`parseResetTime` in `open-sse/services/usage.ts` and `codexUsageQuotas.ts`
already handled `number` reset values with the `< 1e12 ? * 1000 : value`
seconds-vs-ms heuristic, but for `string` inputs it always called
`new Date(str)`. When a provider returned the reset timestamp as a
numeric string (e.g. `"1700000000"`), `new Date(str)` returned Invalid
Date, the try/catch swallowed it, and the function returned `null` —
the reset window was silently dropped from quota snapshots.

Numeric strings (`/^\d+$/`) are now detected and treated as Unix
timestamps with the same seconds-vs-ms heuristic. ISO/parseable strings
are untouched. Applied symmetrically in both parsers.

TDD: 2 failing tests added in `tests/unit/usage-utils.test.ts` for the
seconds-string and ms-string cases; both green after the fix (47/47 in
file, 27/27 in adjacent usage/quota tests).

Inspired-by: decolua/9router#768

Co-authored-by: Zhen <zhen@dkzhen.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants