Created
June 9, 2014 21:14
-
-
Save tjluoma/a4a3bc2b61278243b0e5 to your computer and use it in GitHub Desktop.
Show all Sundays between now and the end of a given year
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/zsh -f | |
## Note: requires `gdate` --> brew install coreutils | |
# What year do you want to stop at? | |
# i.e. "2015" = print all Sundays from now until the end of 2015 | |
STOP='2015' | |
# We need to figure out when the next Sunday is… | |
# Step 1) This is today (will be number 0-7) | |
TODAY=`gdate '+%u'` | |
# Step 2) This is how many days it is until the next Sunday | |
COUNT=`expr 7 - $TODAY` | |
# This is the year we are starting with | |
YEAR=`gdate --date "+${COUNT} day" '+%Y'` | |
# While the 'year' is less than or equal to the STOP year | |
while [ "$YEAR" -le "${STOP}" ] | |
do | |
# calculate and print the date | |
# Note that you can control the format of the date here too | |
gdate --date "+${COUNT} day" '+%B %d, %Y' | |
# increment the counter | |
COUNT=`expr ${COUNT} + 7` | |
# check the resulting year | |
YEAR=`gdate --date "+${COUNT} day" '+%Y'` | |
done | |
exit 0 | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment