From cbb62548fc5651edb92d75c8f32b77940420f67f Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Thu, 16 Jun 2022 19:21:32 +1000 Subject: [PATCH] Fix display of rules missing day when format is "@day;xxxx-yyyy" --- aircon.sh | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/aircon.sh b/aircon.sh index 95b9bf4..5a0b17d 100755 --- a/aircon.sh +++ b/aircon.sh @@ -927,6 +927,25 @@ function weekdaytonum() { echo "$num" } +function weekdaytofull() { + local full + shopt -s nocasematch + num=-1 + case "$1" in + "mon") full="Monday";; + "tue") full="Tuesday";; + "wed") full="Wednesday";; + "thu") full="Thursday";; + "fri") full="Friday";; + "sat") full="Saturday";; + "sun") full="Sunday";; + esac + shopt -u nocasematch + echo "$full" +} + + + function conderror() { error "Invalid condition: $1" echo -e "${RED} Start: $2" @@ -1028,6 +1047,10 @@ function processtimeconditions() { fi endh="$starth" nowh=$(date +%u) + + [[ -n $timestr_human ]] && this_human="o " || this_human=O + this_human=$(printf "${this_human}n _H_%ss_EH_" $(weekdaytofull ${ttok[0]})) + else stype[0]=$(getstrtype ${ttok[0]}) stype[1]=$(getstrtype ${ttok[1]}) @@ -1055,7 +1078,7 @@ function processtimeconditions() { return 1 fi nowh=$(date +%u) - if [[ ${ttok[1]} == ${ttok[2]} ]]; then + if [[ ${ttok[0]} == ${ttok[1]} ]]; then [[ -n $timestr_human ]] && this_human="o " || this_human=O this_human=$(printf "${this_human}n _H_%ss_EH_" ${ttok[0]}) else @@ -1066,7 +1089,7 @@ function processtimeconditions() { conderror "${cond}" "'${ttok[0]}' (${stype[0]})" "'${ttok[1]}' (${stype[1]})" return 1 fi - fi + fi # end if ttokcount if [[ -n $starth ]]; then [[ $db -eq 1 ]] && info " check if $nowh is between $starth and $endh" ok=0 @@ -1086,7 +1109,7 @@ function processtimeconditions() { [[ $ok -eq 0 ]] && nonmatches=$((nonmatches + 1)) [[ $db -eq 1 && $ok -eq 0 ]] && info " $nowh isn't in range $cond" [[ $db -eq 1 && $ok -eq 1 ]] && info " MATCH: $nowh within range $cond" - fi + fi # end if condition matches timestr_human="${timestr_human}${this_human}" if [[ $ok -eq 0 && $keepgoing -eq 0 ]]; then break