From d29fa44f0de3e015fe3c83b5e48164c344f1fc60 Mon Sep 17 00:00:00 2001 From: Steven Baltakatei Sandoval Date: Fri, 10 Jul 2020 04:29:14 +0000 Subject: [PATCH] style(unitproc):timeEpochNS():VAR_NAMES to varNames --- unitproc/bktemp-timeEpochNS | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/unitproc/bktemp-timeEpochNS b/unitproc/bktemp-timeEpochNS index 4c02f23..c490ddf 100644 --- a/unitproc/bktemp-timeEpochNS +++ b/unitproc/bktemp-timeEpochNS @@ -7,40 +7,40 @@ try() { "$@" || die "cannot $*"; } #o timeEpochNS() { # Desc: Get epoch nanoseconds # Usage: timeEpochNS - # Version 0.2.2 + # Version 0.2.3 # Input: arg1: 'date'-parsable timestamp string (optional) # Output: Nanoseconds since 1970-01-01 - # Depends: date 8, yell() + # Depends: date 8, cut 8, yell() # Ref/Attrib: Force base 10 Bash arith with '10#'. https://stackoverflow.com/a/24777667 - local TIME_CURRENT TIME_INPUT TIME_EPOCH_FLOAT TIME_EPOCH_NSFRAC - local TIME_EPOCH_NS + local argTime timeCurrent timeInput timeEpochFloat timeEpochInt + local timeEpochNsFrac timeEpochNs argTime="$1"; # Get Current Time - TIME_CURRENT="$(date --iso-8601=ns)"; # Produce `date`-parsable current timestamp with resolution of 1 nanosecond. + timeCurrent="$(date --iso-8601=ns)"; # Produce `date`-parsable current timestamp with resolution of 1 nanosecond. # Decide to parse current or supplied time ## Check if time argument empty if [[ -z "$argTime" ]]; then ## T: Time argument empty, use current time - TIME_INPUT="$TIME_CURRENT"; + 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 - TIME_INPUT="$argTime"; + timeInput="$argTime"; else ### F: Time argument not valid; exit yell "ERROR:Invalid time argument supplied. Exiting."; exit 1; fi; fi; # Construct and deliver nanoseconds since 1970-01-01 - TIME_EPOCH_FLOAT="$(date --date="$TIME_INPUT" +%s.%N)"; # Save ssss.NNNNNNNNN - TIME_EPOCH_INT="$(echo "$TIME_EPOCH_FLOAT" | cut -d. -f1)"; # Get ssss - TIME_EPOCH_NSFRAC="$(echo "$TIME_EPOCH_FLOAT" | cut -d. -f2)"; # Get NNNNNNNNN - TIME_EPOCH_NS="$(( (10#"$TIME_EPOCH_INT" * 10**9) + (10#"$TIME_EPOCH_NSFRAC") ))"; - echo "$TIME_EPOCH_NS"; + timeEpochFloat="$(date --date="$timeInput" +%s.%N)"; # Save ssss.NNNNNNNNN + timeEpochInt="$(echo "$timeEpochFloat" | cut -d. -f1)"; # Get ssss + timeEpochNsFrac="$(echo "$timeEpochFloat" | cut -d. -f2)"; # Get NNNNNNNNN + timeEpochNs="$(( (10#"$timeEpochInt" * 10**9) + (10#"$timeEpochNsFrac") ))"; + echo "$timeEpochNs"; } # Nanoseconds since 1970-01-01 #==BEGIN sample code== -- 2.30.2