Fix sunrise wait windows on DST change days
daily_sunrise_video.sh and sunrise-audio-capture.sh added wall-clock seconds-since-midnight to a midnight epoch, which is 3600s off on the two days a year the clocks change. Resolve targets with date -d "today HH:MM:SS" instead. sunrise.py now builds local midnight with tz.localize(). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013wi3ZRpfenCe2TRwT4JFMG
This commit is contained in:
@@ -65,14 +65,16 @@ if ! $TEST_MODE; then
|
||||
start_sec=$((sunrise_sec - SUNRISE_PRE_MIN * 60))
|
||||
end_sec=$((sunrise_sec + SUNRISE_POST_MIN * 60))
|
||||
echo "Window: $((start_sec/3600)):$(printf '%02d' $(((start_sec%3600)/60))) → $((end_sec/3600)):$(printf '%02d' $(((end_sec%3600)/60)))"
|
||||
midnight=$(date -d "today 00:00:00" +%s)
|
||||
now_day_sec=$(( $(date +%s) - midnight ))
|
||||
if [ "$now_day_sec" -lt "$end_sec" ]; then
|
||||
wait_sec=$(( end_sec - now_day_sec + 30 ))
|
||||
echo "Waiting ${wait_sec}s for capture window to finish (ends $(date -d "@$(( midnight + end_sec ))" '+%H:%M:%S'))..."
|
||||
# Resolve wall-clock targets through `date -d` instead of adding seconds-since-
|
||||
# midnight to a midnight epoch: on a DST day (23h/25h) the two differ by 3600s.
|
||||
end_epoch=$(date -d "today $(printf '%02d:%02d:%02d' $((end_sec/3600)) $(((end_sec%3600)/60)) $((end_sec%60)))" +%s)
|
||||
now_epoch=$(date +%s)
|
||||
if [ "$now_epoch" -lt "$end_epoch" ]; then
|
||||
wait_sec=$(( end_epoch - now_epoch + 30 ))
|
||||
echo "Waiting ${wait_sec}s for capture window to finish (ends $(date -d "@$end_epoch" '+%H:%M:%S'))..."
|
||||
sleep "$wait_sec"
|
||||
else
|
||||
echo "Capture window already closed at $(date -d "@$(( midnight + end_sec ))" '+%H:%M:%S') — processing available images"
|
||||
echo "Capture window already closed at $(date -d "@$end_epoch" '+%H:%M:%S') — processing available images"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user