Skip to content

fix(rate-limits): parse resets_at with GNU date so time-remaining shows on Linux/Windows#38

Open
marciogranzotto wants to merge 1 commit into
pstuart:mainfrom
marciogranzotto:fix/rate-limits-gnu-date
Open

fix(rate-limits): parse resets_at with GNU date so time-remaining shows on Linux/Windows#38
marciogranzotto wants to merge 1 commit into
pstuart:mainfrom
marciogranzotto:fix/rate-limits-gnu-date

Conversation

@marciogranzotto

Copy link
Copy Markdown
Contributor

Summary

RATE_SHOW_TIME_REMAINING (default: true) never displays anything on Linux or Windows (Git Bash). The resets_at timestamps are parsed only with BSD date syntax:

date -u -j -f "%Y-%m-%dT%H:%M:%S" "${five_hour_reset%%.*}" +%s 2>/dev/null || echo 0

GNU date doesn't support -j/-f, so this silently falls back to epoch 0, the computed remaining time goes negative, and the (2h 15m) / (3d 4h) suffix is skipped — with no error, since stderr is discarded. macOS users are unaffected.

Fix

Adds a small _parse_reset_epoch helper that tries BSD date -j -f first (macOS), then GNU date -d (Linux, Git Bash), keeping 0 as the final fallback. Both call sites (5-hour and 7-day) now use it. No behavior change on macOS.

Testing

  • On Git Bash (Windows): before the fix, output was 5h:24% 🟢 7d:71% 🟡; after, 5h:24% 🟢 (2h 4m) 7d:71% 🟡 (3d 21h).
  • Verified the BSD branch is attempted first and the GNU fallback only runs when -j is unsupported.
  • bash tests/test_utils.sh and bash tests/test_sandbox.sh pass (27/27).

🤖 Generated with Claude Code

…ws on Linux/Windows

The reset timestamps were parsed only with BSD `date -j -f` (macOS).
On GNU date (Linux, Git Bash on Windows) that fails silently, the epoch
falls back to 0, remaining time goes negative, and the "(2h 15m)" /
"(3d 4h)" display never appears even with RATE_SHOW_TIME_REMAINING=true.
Try BSD first, then GNU `date -d`, keeping 0 as the final fallback.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant