File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,34 @@ function bashunit::date::to_epoch() {
1212 ;;
1313 esac
1414
15+ # Normalize ISO 8601: replace T with space, strip Z suffix, strip tz offset
16+ local normalized=" $input "
17+ normalized=" ${normalized/ T/ } "
18+ normalized=" ${normalized% Z} "
19+ # Strip timezone offset (+HHMM or -HHMM) at end for initial parsing
20+ # shellcheck disable=SC2034
21+ local tz_offset=" "
22+ case " $normalized " in
23+ * [+-][0-9][0-9][0-9][0-9])
24+ tz_offset=" ${normalized: -5} "
25+ normalized=" ${normalized% [+-][0-9][0-9][0-9][0-9]} "
26+ ;;
27+ esac
28+
1529 # Format conversion (GNU vs BSD date)
1630 local epoch
17- # Try GNU date first (-d flag)
31+ # Try GNU date first (-d flag) with original input
1832 epoch=$( date -d " $input " +%s 2> /dev/null) && {
1933 echo " $epoch "
2034 return 0
2135 }
36+ # Try GNU date with normalized (space-separated) input
37+ if [[ " $normalized " != " $input " ]]; then
38+ epoch=$( date -d " $normalized " +%s 2> /dev/null) && {
39+ echo " $epoch "
40+ return 0
41+ }
42+ fi
2243 # Try BSD date (-j -f flag) with ISO 8601 datetime + timezone offset
2344 epoch=$( date -j -f " %Y-%m-%dT%H:%M:%S%z" " $input " +%s 2> /dev/null) && {
2445 echo " $epoch "
You can’t perform that action at this time.
0 commit comments