Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ nxf_sleep() {

nxf_date() {
## should return the current timestamp in milliseconds
## note1: some linux silently ignores the `%3N` option and returns the ts in seconds (len==10)
## note2: old date tool ignores the `%3N` option and append that string to the timestamp in seconds
## note3: mac date tools ignores the `%3N` option and the string `3N` is appended to the timestamp in seconds
local ts=$(date +%s%3N);
if [[ ${#ts} == 10 ]]; then echo ${ts}000
elif [[ $ts == *%3N ]]; then echo ${ts/\%3N/000}
elif [[ $ts == *3N ]]; then echo ${ts/3N/000}
elif [[ ${#ts} == 13 ]]; then echo $ts
else echo "Unexpected timestamp value: $ts"; exit 1
## handles GNU coreutils (9-digit %N), uutils coreutils (zero-stripped %N),
## and BSD/macOS date (literal "N" from %N, falling back to second precision)
local s n
s=$(date +%s)
n=$(date +%N)
if [[ $n =~ ^[0-9]+$ ]]; then
n=$(printf '%09d' "$((10#$n))")
echo "$((s * 1000 + 10#${n:0:3}))"
else
echo "$((s * 1000))"
fi
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ nxf_sleep() {
}

nxf_date() {
local ts=$(date +%s%3N);
if [[ ${#ts} == 10 ]]; then echo ${ts}000
elif [[ $ts == *%3N ]]; then echo ${ts/\%3N/000}
elif [[ $ts == *3N ]]; then echo ${ts/3N/000}
elif [[ ${#ts} == 13 ]]; then echo $ts
else echo "Unexpected timestamp value: $ts"; exit 1
local s n
s=$(date +%s)
n=$(date +%N)
if [[ $n =~ ^[0-9]+$ ]]; then
n=$(printf '%09d' "$((10#$n))")
echo "$((s * 1000 + 10#${n:0:3}))"
else
echo "$((s * 1000))"
fi
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ nxf_sleep() {
}

nxf_date() {
local ts=$(date +%s%3N);
if [[ ${#ts} == 10 ]]; then echo ${ts}000
elif [[ $ts == *%3N ]]; then echo ${ts/\%3N/000}
elif [[ $ts == *3N ]]; then echo ${ts/3N/000}
elif [[ ${#ts} == 13 ]]; then echo $ts
else echo "Unexpected timestamp value: $ts"; exit 1
local s n
s=$(date +%s)
n=$(date +%N)
if [[ $n =~ ^[0-9]+$ ]]; then
n=$(printf '%09d' "$((10#$n))")
echo "$((s * 1000 + 10#${n:0:3}))"
else
echo "$((s * 1000))"
fi
}

Expand Down
Loading