test(unitproc):dateTimeShort:Add sample test of nanoseconds
[BK-2020-03.git] / unitproc / bktemp-validateInput
index ef125ad8ae144d8453a71c2a14c294b84f310f1f..2fa708277e08948a3685e0c79f7839ca17b17ccf 100644 (file)
@@ -7,7 +7,7 @@ try() { "$@" || die "cannot $*"; } #o
 validateInput() {
     # Desc: Validates Input
     # Usage: validateInput [str input] [str input type]
 validateInput() {
     # Desc: Validates Input
     # Usage: validateInput [str input] [str input type]
-    # Version: 0.2.2
+    # Version: 0.3.0
     # Input: arg1: string to validate
     #        arg2: string specifying input type (ex:"ssh_pubkey")
     # Output: return code 0: if input string matched specified string type
     # Input: arg1: string to validate
     #        arg2: string specifying input type (ex:"ssh_pubkey")
     # Output: return code 0: if input string matched specified string type
@@ -41,6 +41,18 @@ validateInput() {
     if [[ "$argType" = "integer" ]]; then
        if [[ "$argInput" =~ ^[[:digit:]]*$ ]]; then
            return 0; fi; fi;
     if [[ "$argType" = "integer" ]]; then
        if [[ "$argInput" =~ ^[[:digit:]]*$ ]]; then
            return 0; fi; fi;
+
+    ## time element (year, month, week, day, hour, minute, second)
+    if [[ "$argType" = "time_element" ]]; then
+       if [[ "$argInput" = "year" ]] || \
+              [[ "$argInput" = "month" ]] || \
+              [[ "$argInput" = "week" ]] || \
+              [[ "$argInput" = "day" ]] || \
+              [[ "$argInput" = "hour" ]] || \
+              [[ "$argInput" = "minute" ]] || \
+              [[ "$argInput" = "second" ]]; then
+           return 0; fi; fi;
+    
     # Return error if no condition matched.
     return 1;
 } # Validates strings
     # Return error if no condition matched.
     return 1;
 } # Validates strings
@@ -76,6 +88,11 @@ keyType="integer";
 if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi
 echo "";
 
 if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi
 echo "";
 
+testKey="year"
+keyType="time_element";
+if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi
+echo "";
+
 #==END sample code==
 
 # Author: Steven Baltakatei Sandoval (bktei.com)
 #==END sample code==
 
 # Author: Steven Baltakatei Sandoval (bktei.com)