Created
June 10, 2012 19:34
-
-
Save avh4/2907056 to your computer and use it in GitHub Desktop.
List the weeks between now and a given date
This file contains hidden or 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 | |
# Lists the weeks between now and $1. You may specify the end date in any | |
# way that GNU date accepts, such as "Aug 25", "next year" or "2 months". | |
# | |
# If your system date is BSD date (like on Mac OS X), you will need to install | |
# GNU coreutils, ideally with http://mxcl.github.com/homebrew/ | |
# "brew install coreutils" | |
FORMAT="Week of %b %e, %Y: " | |
DAY_TO_PRINT="Monday" | |
DATE_CMD="gdate" # Use gdate if your system date is BSD date (Mac OS X) | |
# DATE_CMD="date" # Use this if your system date is GNU date (Linux) | |
END_T="`$DATE_CMD -d "$1" +%s`" | |
NEXT_WEEK=0 | |
NEXT="$DAY_TO_PRINT +$NEXT_WEEK week" | |
NEXT_T="`$DATE_CMD -d "$NEXT" +%s`" | |
while [ "$NEXT_T" -lt "$END_T" ]; do | |
gdate -d "$NEXT" +"$FORMAT" | |
NEXT_WEEK="$(($NEXT_WEEK + 1))" | |
NEXT="$DAY_TO_PRINT +$NEXT_WEEK week" | |
NEXT_T="`$DATE_CMD -d "$NEXT" +%s`" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment