From: Masta Fool Date: 2011-12-29T08:20:51+09:00 Subject: Re: Ruby on rails events frequency Fix it.. with a bodge What I do, is create the first event, then move the code that calculates the next event occurrence which pushes the events FORWARD by one day - giving me the wanted result. New code below: ###New Model Action### def create_events_until st = starttime et = endtime p = r_period(period) nst, net = st, et self.events.create(:title => title, :description => description, :all_day => all_day, :starttime => nst, :endtime => net, :user_id => user_id, :remind_at => remind_at, :remind_setting => remind_setting, :remind_value => remind_value, :set_reminder => set_reminder, :calendar_id => calendar_id, :resource_ids => resource_ids) while frequency.send(p).from_now(st) <= END_TIME nst = st = frequency.send(p).from_now(st) net = et = frequency.send(p).from_now(et) self.events.create(:title => title, :description => description, :all_day => all_day, :starttime => nst, :endtime => net, :user_id => user_id, :remind_at => remind_at, :remind_setting => remind_setting, :remind_value => remind_value, :set_reminder => set_reminder, :calendar_id => calendar_id, :resource_ids => resource_ids) if period.downcase == 'monthly' or period.downcase == 'yearly' begin nst = DateTime.parse("#{starttime.hour}:#{starttime.min}:#{starttime.sec}, #{starttime.day}-#{st.month}-#{st.year}") net = DateTime.parse("#{endtime.hour}:#{endtime.min}:#{endtime.sec}, #{endtime.day}-#{et.month}-#{et.year}") rescue nst = net = nil end end end end -- Posted via http://www.ruby-forum.com/.