fix(bklog):Fix initial edge case bug in duration time
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 14 Jul 2020 19:47:38 +0000 (19:47 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 14 Jul 2020 19:47:38 +0000 (19:47 +0000)
exec/bklog

index b4c8257ea8ee9bf782c08fbeaef3429e0e2581c9..a99468a5eaf6297abe13fea82420ea2322ccc5f1 100644 (file)
@@ -11,8 +11,9 @@ dirTmpDefault="/dev/shm"; # Default parent of working directory
 
 # Script Metadata
 scriptName="bklog";             # Define basename of script file.
-scriptVersion="0.1.28-test3";          # Define version of script.
+scriptVersion="0.1.28-test4";          # Define version of script.
 scriptURL="https://gitlab.com/baltakatei/ninfacyzga-01"; # Define wesite hosting this script.
+scriptTimeStartEpoch="$(date +%s)"; # Save start time of script in epoch seconds
 scriptTimeStart="$(date +%Y%m%dT%H%M%S.%N)"; # YYYYmmddTHHMMSS.NNNNNNNNN
 scriptHostname=$(hostname);     # Save hostname of system running this script.
 PATH="$HOME/.local/bin:$PATH";  # Add "$(systemd-path user-binaries)" path in case user apps saved there
@@ -1437,7 +1438,15 @@ main() {
            buffer+=("$line");
        done;
        # Mark time for buffer
-       timeBufferStartEpoch="$timeBufferEndEpoch" && vbm "DEBUG :$fn:timeBufferStartEpoch:$timeBufferStartEpoch";
+       ## Initial time
+       if [[ ! -z "$timeBufferEndEpoch" ]]; then
+           ### Usual case
+           timeBufferStartEpoch="$timeBufferEndEpoch" && vbm "DEBUG :$fn:timeBufferStartEpoch:$timeBufferStartEpoch";
+       else
+           ### Edge case: initial startup
+           timeBufferStartEpoch="$scriptTimeStartEpoch" && vbm "DEBUG :$fn:timeBufferStartEpoch:$timeBufferStartEpoch";
+       fi;
+       ## End Time
        timeBufferEndEpoch="$(date +%s)" && vbm "DEBUG :$fn:timeBufferEndEpoch:$timeBufferEndEpoch";
        # Create dir_tmp if missing
        if ! [[ -d "$dir_tmp" ]]; then