Created
June 6, 2012 22:10
-
-
Save tbeseda/2885141 to your computer and use it in GitHub Desktop.
Get each Wednesday for the rest of this year and all of next
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
dow = 3 # for Wednesday | |
this_year = today.getUTCFullYear() | |
next_year = this_year+1 | |
wednesdays = [] | |
days_in_month = (month, year) -> | |
32 - new Date(year, month, 32).getDate() | |
year_number = this_year | |
while year_number <= next_year | |
month_number = if year_number > this_year then 0 else today.getMonth() | |
while month_number < 12 | |
d = 1 | |
end_of_month = days_in_month(month_number, year_number) | |
while d <= end_of_month | |
date = new Date year_number, month_number, d | |
if date.getDay() is dow | |
wednesdays.push date.toDateString() | |
d++ | |
month_number++ | |
year_number++ | |
wednesdays |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The long way. Should just add 7 to the first known Wednesday 52 times...