From 8a73e6bd2c0fbb15dd85caffe70fe84ace19a4a3 Mon Sep 17 00:00:00 2001 From: Marcio Granzotto Rodrigues Date: Fri, 12 Jun 2026 11:05:37 -0300 Subject: [PATCH] fix(rate-limits): parse resets_at with GNU date so time-remaining shows 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 --- modules/rate-limits.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/rate-limits.sh b/modules/rate-limits.sh index 13ac3ce..132da65 100644 --- a/modules/rate-limits.sh +++ b/modules/rate-limits.sh @@ -192,6 +192,16 @@ _get_projection_status() { get_status "$projected" "$warn_thresh" "$crit_thresh" } +# Parse an ISO-8601 resets_at timestamp (UTC, fractional seconds stripped by the +# caller) to epoch seconds. `date -j -f` is BSD/macOS-only; GNU date (Linux, +# Git Bash on Windows) needs -d. Try both so time-remaining works everywhere. +_parse_reset_epoch() { + local ts="$1" + date -u -j -f "%Y-%m-%dT%H:%M:%S" "$ts" +%s 2>/dev/null || \ + date -u -d "$ts" +%s 2>/dev/null || \ + echo 0 +} + module_rate_limits() { local show_5h="${RATE_SHOW_5H:-true}" local show_7d="${RATE_SHOW_7D:-true}" @@ -310,7 +320,7 @@ module_rate_limits() { # Parse 5-hour reset time and calculate projection if [ -n "$five_hour_reset" ]; then - local five_hour_reset_epoch=$(date -u -j -f "%Y-%m-%dT%H:%M:%S" "${five_hour_reset%%.*}" +%s 2>/dev/null || echo 0) + local five_hour_reset_epoch=$(_parse_reset_epoch "${five_hour_reset%%.*}") five_hour_remaining=$((five_hour_reset_epoch - now)) if [ "$five_hour_remaining" -gt 18000 ]; then five_hour_remaining=18000 @@ -342,7 +352,7 @@ module_rate_limits() { # Parse 7-day reset time and calculate projection if [ -n "$seven_day_reset" ]; then - local seven_day_reset_epoch=$(date -u -j -f "%Y-%m-%dT%H:%M:%S" "${seven_day_reset%%.*}" +%s 2>/dev/null || echo 0) + local seven_day_reset_epoch=$(_parse_reset_epoch "${seven_day_reset%%.*}") seven_day_remaining=$((seven_day_reset_epoch - now)) if [ "$seven_day_remaining" -gt 604800 ]; then seven_day_remaining=604800