diff options
author | Michael Boelen <michael.boelen@cisofy.com> | 2022-10-24 17:21:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-24 17:21:26 +0300 |
commit | 38b7b47c9ca59132fe7f20fbeacbcebe7683ea5e (patch) | |
tree | 721eb93e4311cb65087a79d89925725f1f655126 | |
parent | 490d39f58056fd2f0433e11dc7629528587172c3 (diff) | |
parent | bbe135d56f13f3c05a4a328c504639c6568de8b2 (diff) |
Merge pull request #1340 from HansHoogerwerf/date-nanosecond-support-check
Verify the linux OS supports nanoseconds
-rw-r--r-- | include/functions | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/include/functions b/include/functions index 5b211707..38cc46b3 100644 --- a/include/functions +++ b/include/functions @@ -2562,14 +2562,18 @@ GetTimestamp() { ts=0 - case "${OS}" in - "Linux") + # Detect if the implementation of date supports nanoseconds, + if [ "${OS}" = "Linux" ]; then + current_nanoseconds=$(date "+%N") + # Verify if the result of the command is a number + if [ -n "$current_nanoseconds" ] && [ "$current_nanoseconds" -eq "$current_nanoseconds" ] 2>/dev/null; then ts=$(date "+%s%N") - ;; - *) + else ts=$(date "+%s") - ;; - esac + fi + else + ts=$(date "+%s") + fi echo $ts } |