diff --git a/modules/nextflow/src/main/resources/nextflow/executor/command-run.txt b/modules/nextflow/src/main/resources/nextflow/executor/command-run.txt index 7c267ae96b..f511499cf8 100644 --- a/modules/nextflow/src/main/resources/nextflow/executor/command-run.txt +++ b/modules/nextflow/src/main/resources/nextflow/executor/command-run.txt @@ -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 } diff --git a/modules/nextflow/src/test/resources/nextflow/executor/test-bash-wrapper-with-trace.txt b/modules/nextflow/src/test/resources/nextflow/executor/test-bash-wrapper-with-trace.txt index ddb32e3678..b42f5564bb 100644 --- a/modules/nextflow/src/test/resources/nextflow/executor/test-bash-wrapper-with-trace.txt +++ b/modules/nextflow/src/test/resources/nextflow/executor/test-bash-wrapper-with-trace.txt @@ -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 } diff --git a/modules/nextflow/src/test/resources/nextflow/executor/test-bash-wrapper.txt b/modules/nextflow/src/test/resources/nextflow/executor/test-bash-wrapper.txt index 4ff59eac19..82cc06dd46 100644 --- a/modules/nextflow/src/test/resources/nextflow/executor/test-bash-wrapper.txt +++ b/modules/nextflow/src/test/resources/nextflow/executor/test-bash-wrapper.txt @@ -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 }