Skip to content

Commit dc0d7e1

Browse files
committed
fix(assert): normalize Z suffix to +0000 for date parsing
1 parent a122c56 commit dc0d7e1

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/assert_dates.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,25 @@ function bashunit::date::to_epoch() {
1212
;;
1313
esac
1414

15-
# Normalize ISO 8601: replace T with space, strip Z suffix, strip tz offset
15+
# Handle Z (UTC) suffix explicitly: BusyBox needs TZ=UTC, BSD needs +0000
16+
case "$input" in
17+
*Z)
18+
local utc_input="${input%Z}"
19+
local utc_norm="${utc_input/T/ }"
20+
local epoch
21+
# GNU/BusyBox: parse in explicit UTC
22+
epoch=$(TZ=UTC date -d "$utc_input" +%s 2>/dev/null) && { echo "$epoch"; return 0; }
23+
epoch=$(TZ=UTC date -d "$utc_norm" +%s 2>/dev/null) && { echo "$epoch"; return 0; }
24+
# BSD: use +0000 offset which %z understands
25+
epoch=$(date -j -f "%Y-%m-%dT%H:%M:%S%z" "${utc_input}+0000" +%s 2>/dev/null) && { echo "$epoch"; return 0; }
26+
echo "$input"
27+
return 1
28+
;;
29+
esac
30+
31+
# Normalize ISO 8601: replace T with space, strip tz offset
1632
local normalized="$input"
1733
normalized="${normalized/T/ }"
18-
normalized="${normalized%Z}"
1934
# Strip timezone offset (+HHMM or -HHMM) at end for initial parsing
2035
case "$normalized" in
2136
*[+-][0-9][0-9][0-9][0-9])

0 commit comments

Comments
 (0)