Skip to content

Instantly share code, notes, and snippets.

@zuloo
Created December 30, 2015 15:28
Show Gist options
  • Save zuloo/f2fed0de6ddbc0d25e2e to your computer and use it in GitHub Desktop.
Save zuloo/f2fed0de6ddbc0d25e2e to your computer and use it in GitHub Desktop.
moonphase bash script
#!/bin/bash
moonphase(){
local lp=2551443
local now=$(date -u +"%s")
local newmoon=592500
local phase=$((($now - $newmoon) % $lp))
local phase_number=$((((phase / 86400) + 1)*100000))
# Multiply by 100000 so we can do integer comparison. Go Bash!
if [ $phase_number -lt 184566 ]; then phase_icon="○" # new
elif [ $phase_number -lt 553699 ]; then phase_icon="❩" # waxing crescent
elif [ $phase_number -lt 922831 ]; then phase_icon="◗" # first quarter
elif [ $phase_number -lt 1291963 ]; then phase_icon="◑" # first quarter
elif [ $phase_number -lt 1661096 ]; then phase_icon="●" # full
elif [ $phase_number -lt 2030228 ]; then phase_icon="◐" # waning gibbous
elif [ $phase_number -lt 2399361 ]; then phase_icon="◖" # last quarter
elif [ $phase_number -lt 2768493 ]; then phase_icon="❨" # waning crescent
else
phase_icon="○" # new
fi
echo $phase_icon
}
moonphase
@jamieduk
Copy link

Hi how do I calculate a past dates phase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment