Verify the linux OS supports nanoseconds

Add extra check to verify the linux OS supports nanoseconds. This might not be the case with certain busybox implementations.
This commit is contained in:
HansHoogerwerf 2022-10-17 15:46:40 +02:00 committed by GitHub
parent 490d39f580
commit 98ac5a562a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -2562,15 +2562,17 @@
GetTimestamp() {
ts=0
case "${OS}" in
"Linux")
ts=$(date "+%s%N")
;;
*)
ts=$(date "+%s")
;;
esac
echo $ts
# 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")
fi
fi
echo $ts
}
Register() {