Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,26 @@

helpers do
def second_wednesday_of(month, year)
date = Date.parse("#{year}/#{month}/07")
found = false
while(!found) do
date = date+1
next unless date.wednesday?
next unless (date - 14).month != date.month
found = true
date = Date.new(year, month, 1)

if date.wednesday?
date + 7
else
wday = date.wday
days = wday > 3 ? wday - 3 : wday + 4
date + (14 - days)
end
date
end

def next_event_date(from_date = Date.today)
if second_wednesday_of(from_date.month, from_date.year) > from_date
second_wednesday_of(from_date.month, from_date.year)
next_event = second_wednesday_of(from_date.month, from_date.year)

if next_event > from_date
next_event
else
next_month = from_date+30
second_wednesday_of(next_month.month, next_month.year)
next_month = from_date.next_month
next_month_beginning = next_month - (next_month.day + 1)
next_event_date(next_month_beginning)
end
end

Expand Down