Skip to content

Commit 314c79f

Browse files
fix: support comma decimal separator in shell clock
1 parent 118030a commit 314c79f

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Fixed
1010
- Fix spying on `echo` or `printf` causing bashunit to hang due to infinite recursion (#607)
1111
- Fix invalid `.env.example` coverage threshold entry and copy `.env.example` to `.env` in CI test workflows so configuration parse errors are caught during automated test runs
12+
- Fix `clock::now` shell-time parsing when `EPOCHREALTIME` uses a comma decimal separator
1213

1314
## [0.34.1](https://github.com/TypedDevs/bashunit/compare/0.34.0...0.34.1) - 2026-03-20
1415

src/clock.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ EOF
113113
shell)
114114
# shellcheck disable=SC2155
115115
local shell_time="$(bashunit::clock::shell_time)"
116-
local seconds="${shell_time%%.*}"
117-
local microseconds="${shell_time#*.}"
116+
local seconds="${shell_time%%[.,]*}"
117+
local microseconds="${shell_time#*[.,]}"
118+
if [ "$seconds" = "$shell_time" ]; then
119+
microseconds=""
120+
fi
118121
# Pad to 6 digits and strip leading zeros for arithmetic
119122
microseconds="${microseconds}000000"
120123
microseconds="${microseconds:0:6}"

tests/unit/clock_test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ function test_now_prefers_shell_time_over_perl() {
124124
assert_same "1234567890000" "$(bashunit::clock::now)"
125125
}
126126

127+
function test_now_handles_shell_time_with_comma_decimal_separator() {
128+
bashunit::mock bashunit::clock::shell_time <<<"1234,567890"
129+
130+
assert_same "1234567890000" "$(bashunit::clock::now)"
131+
}
132+
127133
function test_now_prefers_python_over_node() {
128134
bashunit::mock bashunit::clock::shell_time mock_non_existing_fn
129135
bashunit::mock date mock_non_existing_fn

0 commit comments

Comments
 (0)