Every other week recurring event


I have the code for computing a weekly event:

(start_date…end_date).select{|d| d.wday == wday}

but I am wondering if anyone has any ideas for using this to figure
out a recurring event for every other week. Is it possible to somehow
specify every other within the .select method? Any other
implementation ideas?


here’s one way - not a one-liner, but not too complex:

start_date = DateTime.parse(‘2008-01-01’)
end_date = DateTime.parse(‘2008-04-01’)

range = (start_date…end_date)

wday = 1
use_this = false
every_other = []

range.each do |date|
every_other << date if date.wday == wday && use_this
use_this = !use_this

puts every_other.inspect