From: Steven Baltakatei Sandoval Date: Sat, 11 Jul 2020 04:32:26 +0000 (+0000) Subject: fix(bklog):Add missing function dateTimeShort() X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02.git/commitdiff_plain/8681fe1b75cc202996b4c8fbe86dbdec685b87d1?ds=sidebyside;hp=99f6bd4e6c6a6e51ffb667c51c91275ce927965c fix(bklog):Add missing function dateTimeShort() --- diff --git a/exec/bklog b/exec/bklog index 49ec813..f265271 100644 --- a/exec/bklog +++ b/exec/bklog @@ -11,7 +11,7 @@ dirTmpDefault="/dev/shm"; # Default parent of working directory # Script Metadata scriptName="bklog"; # Define basename of script file. -scriptVersion="0.1.10"; # Define version of script. +scriptVersion="0.1.11"; # Define version of script. scriptURL="https://gitlab.com/baltakatei/ninfacyzga-01"; # Define wesite hosting this script. scriptTimeStart="$(date +%Y%m%dT%H%M%S.%N)"; # YYYYmmddTHHMMSS.NNNNNNNNN scriptHostname=$(hostname); # Save hostname of system running this script. @@ -355,6 +355,37 @@ dateShort(){ dateCurrentShort="$(date -d "$timeInput" +%Y%m%d)"; # Produce separator-less current date with resolution 1 day. echo "$dateCurrentShort"; } # Get YYYYmmdd +dateTimeShort(){ + # Desc: Timestamp without separators (YYYYmmddTHHMMSS+zzzz) + # Usage: dateTimeShort ([str date]) + # Version 1.1.1 + # Input: arg1: 'date'-parsable timestamp string (optional) + # Output: stdout: timestamp (ISO-8601, no separators) + # Depends: yell + local argTime timeCurrent timeInput timeCurrentShort + + argTime="$1"; + # Get Current Time + timeCurrent="$(date --iso-8601=seconds)" ; # Produce `date`-parsable current timestamp with resolution of 1 second. + # Decide to parse current or supplied date + ## Check if time argument empty + if [[ -z "$argTime" ]]; then + ## T: Time argument empty, use current time + timeInput="$timeCurrent"; + else + ## F: Time argument exists, validate time + if date --date="$argTime" 1>/dev/null 2>&1; then + ### T: Time argument is valid; use it + timeInput="$argTime"; + else + ### F: Time argument not valid; exit + yell "ERROR:Invalid time argument supplied. Exiting."; exit 1; + fi + fi + # Construct and deliver separator-les date string + timeCurrentShort="$(date -d "$timeInput" +%Y%m%dT%H%M%S%z)"; + echo "$timeCurrentShort"; +} # Get YYYYmmddTHHMMSS±zzzz setTimeZoneEV(){ # Desc: Set time zone environment variable TZ # Usage: setTimeZoneEV arg1