Created
December 30, 2015 15:28
-
-
Save zuloo/f2fed0de6ddbc0d25e2e to your computer and use it in GitHub Desktop.
moonphase bash script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi how do I calculate a past dates phase?