@@ -4,22 +4,13 @@ function clock::now() {
44 local shell_time
55 local attempts=()
66
7- # 1. Try using native shell EPOCHREALTIME (if available)
8- attempts+=(" EPOCHREALTIME" )
9- if shell_time=" $( clock::shell_time) " ; then
10- local seconds=" ${shell_time%% .* } "
11- local microseconds=" ${shell_time#* .} "
12- math::calculate " ($seconds * 1000000000) + ($microseconds * 1000)"
13- return 0
14- fi
15-
16- # 2. Try Perl with Time::HiRes
7+ # 1. Try Perl with Time::HiRes
178 attempts+=(" Perl" )
189 if dependencies::has_perl && perl -MTime::HiRes -e " " & > /dev/null; then
1910 perl -MTime::HiRes -e ' printf("%.0f\n", Time::HiRes::time() * 1000000000)' && return 0
2011 fi
2112
22- # 3 . Try Python 3 with time module
13+ # 2 . Try Python 3 with time module
2314 attempts+=(" Python" )
2415 if dependencies::has_python; then
2516 python - << 'EOF '
2920 return 0
3021 fi
3122
32- # 4 . Try Node.js
23+ # 3 . Try Node.js
3324 attempts+=(" Node" )
3425 if dependencies::has_node; then
3526 node -e ' process.stdout.write((BigInt(Date.now()) * 1000000n).toString())' && return 0
3627 fi
37- # 5 . Windows fallback with PowerShell
28+ # 4 . Windows fallback with PowerShell
3829 attempts+=(" PowerShell" )
3930 if check_os::is_windows && dependencies::has_powershell; then
4031 powershell -Command "
4637 " && return 0
4738 fi
4839
49- # 6 . Unix fallback using `date +%s%N` (if not macOS or Alpine)
40+ # 5 . Unix fallback using `date +%s%N` (if not macOS or Alpine)
5041 attempts+=(" date" )
5142 if ! check_os::is_macos && ! check_os::is_alpine; then
5243 local result
5748 fi
5849 fi
5950
51+ # 6. Try using native shell EPOCHREALTIME (if available)
52+ attempts+=(" EPOCHREALTIME" )
53+ if shell_time=" $( clock::shell_time) " ; then
54+ local seconds=" ${shell_time%% .* } "
55+ local microseconds=" ${shell_time#* .} "
56+ math::calculate " ($seconds * 1000000000) + ($microseconds * 1000)"
57+ return 0
58+ fi
59+
6060 # 7. All methods failed
6161 printf " clock::now implementations tried: %s\n" " ${attempts[*]} " >&2
6262 echo " "
0 commit comments