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
44 changes: 18 additions & 26 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,48 +73,40 @@
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
end
date = date.next_day until date.wednesday?
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)
second_wednesday_of_this_month = second_wednesday_of(from_date.month, from_date.year)
if second_wednesday_of_this_month > from_date
second_wednesday_of_this_month
else
next_month = from_date+30
next_month = from_date.next_month
second_wednesday_of(next_month.month, next_month.year)
end
end

def next_tb_event_date
found = false
current_date = Date.today
while(!found) do
current_date = next_event_date(current_date)
next if [1, 4, 7, 10].include?(current_date.month)
found = true
end
current_date
next_event { |date| not third_month?(date) }
end

def next_ifp_event_date
found = false
current_date = Date.today
while(!found) do
current_date = next_event_date(current_date)
next unless [1, 4, 7, 10].include?(current_date.month)
found = true
end
current_date
next_event { |date| third_month?(date) }
end

def next_event_is_ifp?
next_event_date == next_ifp_event_date
end

def next_event(&block)
date = next_event_date
date = next_event_date(date) until block.call(date)
date
end

def third_month?(date)
third_months = [1, 4, 7, 10]
third_months.include?(date.month)
end
end