def update_dates events events find_each do event if event repeats yea

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def update_dates(events)
events.find_each do |event|
if event.repeats == 1.year.seconds
event.update_attribute(:datetime, event.datetime +
(Date.today.year - event.datetime.year).years) if event.datetime.to_date < Date.today
event.update_attribute(:datetime, event.datetime +
1.year) if event.datetime.to_date < Date.today
elsif event.repeats == 1.month.seconds
event.update_attribute(:datetime, event.datetime +
((Date.today.year * 12 + Date.today.month) -
(event.datetime.year * 12 + event.datetime.month)).months) if event.datetime.to_date < Date.today
event.update_attribute(:datetime, event.datetime +
1.month) if event.datetime.to_date < Date.today
elsif event.repeats == 1.day.seconds
event.update_attribute(:datetime, event.datetime +
(Date.today - event.datetime.to_date).numerator.days) if event.datetime.to_date < Date.today
end
end
@today = events.where('datetime >= ? AND datetime <= ?', DateTime.now.beginning_of_day, DateTime.now.end_of_day)
.order(datetime: :asc, title: :asc)
@future = events.where('datetime > ?', DateTime.now.end_of_day)
.order(datetime: :asc, title: :asc)
@past = events.where('datetime < ?', DateTime.now.beginning_of_day)