skeledance/set-sky-time.sh
vini 2779cb2bb9 Force C locale for sky offset decimal point
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015HtPHsTnDcLVSCiF5FGHZj
2026-07-19 21:42:33 -03:00

18 lines
632 B
Bash
Executable file

#!/usr/bin/env bash
# Pula o relógio do céu para hoje às HH:MM (ex.: ./set-sky-time.sh 06:15).
# "off" (ou sem argumento) volta ao tempo real. Combina com o timelapse.
STATE_FILE=/tmp/skeledance-sky-offset
TARGET=${1:-off}
if [ "$TARGET" = "off" ]; then
printf '0\n' > "$STATE_FILE"
printf 'Relógio do céu em tempo real\n'
exit 0
fi
target_epoch=$(date -d "today $TARGET" +%s) || exit 2
now_epoch=$(date +%s)
offset_h=$(LC_ALL=C awk "BEGIN { printf \"%.4f\", ($target_epoch - $now_epoch) / 3600 }")
printf '%s\n' "$offset_h" > "$STATE_FILE"
printf 'Relógio do céu em %s de hoje (offset %sh)\n' "$TARGET" "$offset_h"