Skip to content

Instantly share code, notes, and snippets.

@mdawaffe
Last active October 22, 2015 05:55
Show Gist options
  • Save mdawaffe/f19820344643e9d16ce2 to your computer and use it in GitHub Desktop.
Save mdawaffe/f19820344643e9d16ce2 to your computer and use it in GitHub Desktop.
Calculates the Date of Mardi Gras from `ncal -e`
#!/bin/bash
function usage {
echo "$0 [-n NUMBER] [YEAR]"
}
date -j &> /dev/null
if [ $? -eq 0 ]; then
# OS X
function mardigras {
date -j -v -47d -f '%B %e %Y' "$( ncal -e $1 )" +'%Y-%m-%d'
}
else
# LINUX
function mardigras {
date -d "$( ncal -e $1 ) -47 days" +'%Y-%m-%d'
}
fi
declare -i NUMBER YEAR i
NUMBER=1
while getopts :hn: OPT; do
case "$OPT" in
h)
usage
exit 0
;;
n)
NUMBER=$OPTARG
shift; shift
;;
:)
usage
exit 1
;;
esac
done
YEAR=${1:-$( date +%Y )}
for (( i=0; i<NUMBER; ++i)); do
mardigras $(( i + YEAR ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment