From f4bae78730d9fbd67474f8134f5f73071805f1f2 Mon Sep 17 00:00:00 2001 From: Nacho Rivera <59198746+n4ch04@users.noreply.github.com> Date: Mon, 23 May 2022 09:28:56 +0200 Subject: [PATCH] Timestamp to date casting issues solved (#1154) * fix(date): Deleted @ char before date argument * fix(date): Use @ only when input is epoch --- include/os_detector | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/os_detector b/include/os_detector index e96baf13..3058fc99 100644 --- a/include/os_detector +++ b/include/os_detector @@ -36,7 +36,14 @@ gnu_timestamp_to_date() { # remove fractions of a second TIMESTAMP_TO_CONVERT=$(cut -f1 -d"." <<< "${1}") - OUTPUT_DATE=$("${DATE_CMD}" -d @"${TIMESTAMP_TO_CONVERT}" +'%Y-%m-%d') + if ! "${DATE_CMD}" -d "${TIMESTAMP_TO_CONVERT}" +%s > /dev/null 2>&1; + then + # If input is epoch use the @ + OUTPUT_DATE=$("${DATE_CMD}" -d @"${TIMESTAMP_TO_CONVERT}" +'%Y-%m-%d') + else + # If input is not epoch dont use @ + OUTPUT_DATE=$("${DATE_CMD}" -d "${TIMESTAMP_TO_CONVERT}" +'%Y-%m-%d') + fi echo "${OUTPUT_DATE}" } bsd_timestamp_to_date() {