Skip to content

Instantly share code, notes, and snippets.

@tbeseda
Created June 6, 2012 22:10
Show Gist options
  • Save tbeseda/2885141 to your computer and use it in GitHub Desktop.
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
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
@tbeseda
Copy link
Author

tbeseda commented Jun 6, 2012

The long way. Should just add 7 to the first known Wednesday 52 times...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment