Merge branch 'master' into develop
[BK-2020-03.git] / unitproc / bktemp-setTimeZoneEV
index 6933752c04f5730fb0fcbd6f641b90d04b3d47ca..f51e16a787f4d41f934988f5bdf58da91fefeda6 100644 (file)
@@ -8,40 +8,42 @@ try() { "$@" || die "cannot $*"; }
 setTimeZoneEV(){
     # Desc: Set time zone environment variable TZ
     # Usage: setTimeZoneEV arg1
-    # Input: arg1: 'date'-compatible timezone string (ex: "America/New_York")
+    # Version 0.1.3
+    # In : arg1: 'date'-compatible timezone string (ex: "America/New_York")
     #        TZDIR env var (optional; default: "/usr/share/zoneinfo")
-    # Output: exports TZ
+    # Out: exports TZ (env var)
     #         exit code 0 on success
     #         exit code 1 on incorrect number of arguments
     #         exit code 2 if unable to validate arg1
-    # Depends: yell, die, try
-    ARG1="$1"
-    local tzDir returnState
+    # Depends: bash 5.0.3, printenv 8.30, yell()
+    local tzDir returnState argTimeZone
+
+    argTimeZone="$1";
     if ! [[ $# -eq 1 ]]; then
        yell "ERROR:Invalid argument count.";
        return 1;
-    fi
+    fi;
 
     # Read TZDIR env var if available
     if printenv TZDIR 1>/dev/null 2>&1; then
        tzDir="$(printenv TZDIR)";
     else
        tzDir="/usr/share/zoneinfo";
-    fi
+    fi;
     
     # Validate TZ string
-    if ! [[ -f "$tzDir"/"$ARG1" ]]; then
+    if ! [[ -f "$tzDir"/"$argTimeZone" ]]; then
        yell "ERROR:Invalid time zone argument.";
        return 2;
     else
     # Export ARG1 as TZ environment variable
-       TZ="$ARG1" && export TZ && returnState="true";
-    fi
+       TZ="$argTimeZone" && export TZ && returnState="true";
+    fi;
 
     # Determine function return code
     if [ "$returnState" = "true" ]; then
        return 0;
-    fi
+    fi;
 } # Exports TZ environment variable
 
 #==BEGIN sample code==
@@ -66,6 +68,8 @@ date --iso-8601=seconds
 cmd4="setTimeZoneEV Pacific/Lemuria"
 echo "Running:$cmd4"; $cmd4; echo "Exit code:$?"
 date --iso-8601=seconds; echo "==============="; sleep 2
+
+try setTimeZoneEV Atlantic/Atlantis
 #==END sample code==
 
 # Author: Steven Baltakatei Sandoval