Skip to content

Commit 2289338

Browse files
authored
test(log): make --since today test timezone-aware for CI (#6)
1 parent 582c520 commit 2289338

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

tests/log_script.bats

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,26 @@ EOF
363363
write_fixture
364364
run_log --since today --format raw
365365
[ "$status" -eq 0 ]
366-
# All four fixture entries are within the last 2 hours, so they should
367-
# all survive the today cutoff.
366+
# Count how many fixture entries are actually within "today" in local tz.
367+
# The 2h-old entry may have fallen into yesterday when the test runs
368+
# within 2 hours of local midnight (common on UTC-running CI).
369+
local now midnight expected
370+
now="$(date +%s)"
371+
if [ "$(uname -s)" = "Darwin" ]; then
372+
midnight="$(date -j -f '%Y-%m-%d %H:%M:%S' "$(date +%Y-%m-%d) 00:00:00" +%s)"
373+
else
374+
midnight="$(date -d "$(date +%Y-%m-%d) 00:00:00" +%s)"
375+
fi
376+
expected=0
377+
for offset in 7200 1800 300 0; do
378+
local ts=$((now - offset))
379+
[ "$ts" -ge "$midnight" ] && expected=$((expected + 1))
380+
done
368381
local n
369382
n="$(printf '%s\n' "$output" | grep -c '"ts":' || true)"
370-
[ "$n" -eq 4 ]
383+
[ "$n" -eq "$expected" ]
384+
# At minimum the "now" entry must survive.
385+
[ "$n" -ge 1 ]
371386
}
372387

373388
@test "--since 30d keeps all fixture entries" {

0 commit comments

Comments
 (0)