diff --git a/sunset-alarm b/sunset-alarm index 6db2518..45a1c03 100755 --- a/sunset-alarm +++ b/sunset-alarm @@ -165,8 +165,7 @@ while true; do CURRENT_TIME=$(date +%s) # Check if we need to fetch new sunset time for a new day. - if [[ "$LAST_DATE" != "$TODAY" \ - || "$SUNSET_EPOCH" == 0 || -z "$SUNSET_TIME" ]] + if [[ "$LAST_DATE" != "$TODAY" || "$SUNSET_EPOCH" == 0 ]] then LAST_DATE="$TODAY" @@ -184,7 +183,7 @@ while true; do continue } - if [[ -z "$SUNSET_TIME" ]]; then + if [[ "$SUNSET_EPOCH" == 0 ]]; then echo "ERROR: Sunset time is still null. Retrying in 5 minutes." >&2 sleep 300 continue @@ -208,11 +207,11 @@ while true; do MIDNIGHT=$(date -d "${TODAY} +1 day" +%s) # Alert while current time is within the window (from window start until midnight). - if [[ -n "$SUNSET_TIME" && "$SUNSET_EPOCH" -ge 0 \ + if [[ "$SUNSET_EPOCH" -ge 0 \ && "$CURRENT_TIME" -ge "$ALERT_WINDOW_START" \ && "$CURRENT_TIME" -lt "$MIDNIGHT" ]] then - echo "Alert time has been reached for $SUNSET_TIME, show message." + echo "Alert time has been reached, show message." show_alert echo "Alert has been dismissed, sleeping for 5 minutes." sleep 290