Merge pull request #1340 from HansHoogerwerf/date-nanosecond-support-check

Verify the linux OS supports nanoseconds
This commit is contained in:
Michael Boelen 2022-10-24 16:21:26 +02:00 committed by GitHub
commit 38b7b47c9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}