Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save willbchang/eddf4c599d07285206477d33af3edf89 to your computer and use it in GitHub Desktop.
Save willbchang/eddf4c599d07285206477d33af3edf89 to your computer and use it in GitHub Desktop.
Off Work Time
#!/bin/zsh
# Get today's date in YYYY-MM-DD format
TODAY=$(date '+%Y-%m-%d')
# Find the first "Display is turned on" event for today
WAKE_TIME=$(pmset -g log | \
grep -m 1 "${TODAY}.*Display is turned on" | \
grep -oE "[0-9]+:[0-9]+:[0-9]+")
if [ -z "$WAKE_TIME" ]; then
echo "No display wake event found for today ($TODAY)"
exit 1
fi
# Add 9 hours to the time
# Convert time to seconds, add 9 hours (32400 seconds), convert back
ADJUSTED_TIME=$(date -j -f "%H:%M:%S" "$WAKE_TIME" "+%s" 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Error: Could not parse time format"
exit 1
fi
# Add 9 hours (32400 seconds)
ADJUSTED_TIME=$((ADJUSTED_TIME + 32400))
# Convert back to HH:MM:SS format
FINAL_TIME=$(date -j -f "%s" "$ADJUSTED_TIME" "+%H:%M:%S" 2>/dev/null)
echo "$FINAL_TIME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment