projects
/
BK-2020-03.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat(user/git-bk-find-file):Show ISO 8601 time along with commit
[BK-2020-03.git]
/
unitproc
/
bkdstcountdown
diff --git
a/unitproc/bkdstcountdown
b/unitproc/bkdstcountdown
index ee3b094ee236594d575930beca807a4360ba59fd..4e3efe81182423551053a93fc0ac34f5d7281394 100755
(executable)
--- a/
unitproc/bkdstcountdown
+++ b/
unitproc/bkdstcountdown
@@
-1,7
+1,5
@@
#!/bin/bash
#!/bin/bash
-# Date: 2020-02-13T23:14Z; baltakatei>
-
# Description: This script outputs days until the next time zone
# discontinuity using 'zdump' and 'date'.
# Description: This script outputs days until the next time zone
# discontinuity using 'zdump' and 'date'.
@@
-9,25
+7,28
@@
SCRIPT_TZ="America/Los_Angeles" # Timezone to check for discontinuities
#=================================================
SCRIPT_TZ="America/Los_Angeles" # Timezone to check for discontinuities
#=================================================
-echoerr() {
- echo "$@" 1>&2;
-}
+yell() { echo "$0: $*" >&2; } # Yell, Die, Try Three-Fingered Claw technique; # Ref/Attrib: https://stackoverflow.com/a/25515370
+die() { yell "$*"; exit 111; }
+
try() { "$@" || die "cannot $*";
}
# Declare variables
declare -a datesDiscontArray #array
SCRIPT_YEAR=$(date +%Y)
SCRIPT_YEAR_NEXT=$(( $(date +%Y) + 1))
# Declare variables
declare -a datesDiscontArray #array
SCRIPT_YEAR=$(date +%Y)
SCRIPT_YEAR_NEXT=$(( $(date +%Y) + 1))
+SCRIPT_YEAR_NEXT2=$(( $(date +%Y) + 2))
SCRIPT_RUN_DATE_SECONDS=$(date +%s)
# Save zdump output for SCRIPT_YEAR (for how multiline data saved in variable, see https://stackoverflow.com/a/613580 )
SCRIPT_RUN_DATE_SECONDS=$(date +%s)
# Save zdump output for SCRIPT_YEAR (for how multiline data saved in variable, see https://stackoverflow.com/a/613580 )
-datesDiscont="$(zdump -c
$SCRIPT_YEAR_NEXT -v $SCRIPT_TZ | grep $SCRIPT_YEAR
| awk '{ print $2 " " $3 " " $4 " " $5 " " $6 " " $7 }'; echo)"
+datesDiscont="$(zdump -c
"$SCRIPT_YEAR","$SCRIPT_YEAR_NEXT2" -v $SCRIPT_TZ | grep "$SCRIPT_YEAR\|$SCRIPT_YEAR_NEXT"
| awk '{ print $2 " " $3 " " $4 " " $5 " " $6 " " $7 }'; echo)"
if [ -z "$datesDiscont" ]; then
if [ -z "$datesDiscont" ]; then
- echo "No time discontinuity this year."
- exit 1
-fi
+ echo "No time discontinuity this year."
;
+ exit 1
;
+fi
;
-###echoerr "datesDiscont:--""$datesDiscont""--"
+###yell "DEBUG:datesDiscont----------";
+###echo "$datesDiscont" 1>&2;
+###yell "DEBUG:-----------";
# Count lines in datesDiscont (for counting lines in a variable, see https://stackoverflow.com/a/6314682 )
#datesDiscontLineCount=$(echo "$datesDiscont" | wc -l)
# Count lines in datesDiscont (for counting lines in a variable, see https://stackoverflow.com/a/6314682 )
#datesDiscontLineCount=$(echo "$datesDiscont" | wc -l)
@@
-39,21
+40,35
@@
while IFS= read -r line; do
datesDiscontArray+=($(date --date="$line" +%s))
#echo ${datesDiscontArray[-1]}
done <<< "$datesDiscont"
datesDiscontArray+=($(date --date="$line" +%s))
#echo ${datesDiscontArray[-1]}
done <<< "$datesDiscont"
-#
echoerr
${datesDiscontArray[@]}
+#
yell
${datesDiscontArray[@]}
# Sort datesDiscontArray (see https://stackoverflow.com/a/11789688 )
IFS=$'\n' datesDiscontArray=($(sort <<<"${datesDiscontArray[*]}"))
unset IFS
# Sort datesDiscontArray (see https://stackoverflow.com/a/11789688 )
IFS=$'\n' datesDiscontArray=($(sort <<<"${datesDiscontArray[*]}"))
unset IFS
+###yell "DEBUG:";
+###yell "DEBUG:datesDiscontArray:";
+###yell "${datesDiscontArray[@]}";
+###yell "DEBUG:";
+
# Get earliest date in datesDiscontArray that isn't in the past.
for discontinuityDate in "${datesDiscontArray[@]}"; do
# Get earliest date in datesDiscontArray that isn't in the past.
for discontinuityDate in "${datesDiscontArray[@]}"; do
- ###
echoerr "
Discontinuity date (seconds):"$discontinuityDate
- ###
echoerr "
SCRIPT_RUN_DATE_SECONDS :"$SCRIPT_RUN_DATE_SECONDS
+ ###
yell "DEBUG:
Discontinuity date (seconds):"$discontinuityDate
+ ###
yell "DEBUG:
SCRIPT_RUN_DATE_SECONDS :"$SCRIPT_RUN_DATE_SECONDS
if [ $discontinuityDate -gt $SCRIPT_RUN_DATE_SECONDS ]; then
if [ $discontinuityDate -gt $SCRIPT_RUN_DATE_SECONDS ]; then
- ###
echoerr
"DEBUG:Date in future."
+ ###
yell
"DEBUG:Date in future."
nextDiscontDate="$discontinuityDate"
break
fi
done
nextDiscontDate="$discontinuityDate"
break
fi
done
+# Check that nextDiscontDate is not empty
+if [ -z "$nextDiscontDate" ]; then
+ echo "ERROR:nextDiscontDate empty"
+fi;
+
+
+###yell "DEBUG:nextDiscontDate:$nextDiscontDate";
+###yell "DEBUG:SCRIPT_RUN_DATE_SECONDS:$SCRIPT_RUN_DATE_SECONDS";
+
echo $(( ( $nextDiscontDate - $SCRIPT_RUN_DATE_SECONDS )/86400 ))" days" # Days until next discontinuity date
echo $(( ( $nextDiscontDate - $SCRIPT_RUN_DATE_SECONDS )/86400 ))" days" # Days until next discontinuity date