From fae03c94d91d9752f9467645162a4c77e7605f5b Mon Sep 17 00:00:00 2001 From: Hyperling Date: Thu, 29 Oct 2026 19:05:01 -0700 Subject: [PATCH] ASked agent to fix the program using sunset time rather than midnight. Seems to be working properly now. --- sunset-alarm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sunset-alarm b/sunset-alarm index 9be13ff..be86791 100755 --- a/sunset-alarm +++ b/sunset-alarm @@ -149,17 +149,20 @@ while true; do # Calculate alert window start (sunset minus specified minutes) ALERT_WINDOW_START=$(( SUNSET_EPOCH - (MINUTES * 60) )) - # Alert while current time is within the window (from window start until sunset) + # Calculate midnight of the current day + MIDNIGHT=$(date -d "${TODAY} +1 day" +%s) + + # Alert while current time is within the window (from window start until midnight) if [ "$CURRENT_TIME" -ge "$ALERT_WINDOW_START" ] && \ - [ "$CURRENT_TIME" -lt "$SUNSET_EPOCH" ]; then + [ "$CURRENT_TIME" -lt "$MIDNIGHT" ]; then show_alert sleep 5 # Re-alert every 5 minutes while in alert window else sleep 60 fi - # Reset when we've passed sunset so we fetch new time tomorrow - if [ "$CURRENT_TIME" -ge "$SUNSET_EPOCH" ]; then + # Reset when we've passed midnight so we fetch new time tomorrow + if [ "$CURRENT_TIME" -ge "$MIDNIGHT" ]; then LAST_DATE="" fi done