Forum: Ruby on Rails Every other week recurring event

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F677fa685a2cfe8aff31f161062db3d3?d=identicon&s=25 David (Guest)
on 2008-11-11 12:17
(Received via mailing list)
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?
D69d23d8e811e8ab2a8593380d6ede63?d=identicon&s=25 Jeff Emminger (jemminger)
on 2008-11-11 19:55
(Received via mailing list)
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
This topic is locked and can not be replied to.