Ruby on rails events frequency

I’m using the JQuery full calendar in one of my rails applications,
however I’ve spotted (what I believe to be a bug) which is really
bugging me as I can’t fix it.

Lets say my configured “END_TIME” is 31st December 2011 00:00:00 and I
create a daily event from 1st December 2011 16:20 - 17:20, to the
“END_TIME” the events are created from the 1st to the 29th. If I then
for example create a weekly event, occurring every 1 weeks from 1st
December 2011 16:20 - 17:20 to 31 to the “END_TIME” It stops on the 22nd
of December 2011 (1 week before its meant to)

It looks to me like the way events are created, its cutting short by 1x
the frequency but I’m unsure how to correctly fix this.

The code from the model is below.

##model##
def after_create
create_events_until
end

def create_events_until
st = starttime
et = endtime
p = r_period(period)
nst, net = st, et

while frequency.send§.from_now(st) <= (END_TIME)
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)
nst = st = frequency.send§.from_now(st)
net = et = frequency.send§.from_now(et)

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

def r_period(period)
case period
when ‘Daily’
p = ‘days’
when “Weekly”
p = ‘weeks’
when “Monthly”
p = ‘months’
when “Yearly”
p = ‘years’
end
return p
end
##end model##

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

-----Messaggio originale-----
Da: Masta Fool [mailto:[email protected]]
Inviato: mercoled 28 dicembre 2011 19:49
A: ruby-talk ML
Oggetto: Ruby on rails events frequency

I’m using the JQuery full calendar in one of my rails applications,
however
I’ve spotted (what I believe to be a bug) which is really bugging me as
I
can’t fix it.

Lets say my configured “END_TIME” is 31st December 2011 00:00:00 and I
create a daily event from 1st December 2011 16:20 - 17:20, to the
“END_TIME”
the events are created from the 1st to the 29th. If I then for example
create a weekly event, occurring every 1 weeks from 1st December 2011
16:20

  • 17:20 to 31 to the “END_TIME” It stops on the 22nd of December 2011 (1
    week before its meant to)

It looks to me like the way events are created, its cutting short by 1x
the
frequency but I’m unsure how to correctly fix this.

The code from the model is below.

##model##
def after_create
create_events_until
end

def create_events_until
st = starttime
et = endtime
p = r_period(period)
nst, net = st, et

while frequency.send(p).from_now(st) <= (END_TIME)
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)
nst = st = frequency.send(p).from_now(st)
net = et = frequency.send(p).from_now(et)

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

def r_period(period)
case period
when ‘Daily’
p = ‘days’
when “Weekly”
p = ‘weeks’
when “Monthly”
p = ‘months’
when “Yearly”
p = ‘years’
end
return p
end
##end model##


Posted via http://www.ruby-forum.com/.


Caselle da 1GB, trasmetti allegati fino a 3GB e in piu’ IMAP, POP3 e
SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
Capodanno a Riccione, Pacchetto Relax: Mezza Pensione + bagno turco +
solarium + massaggio. Wifi e parcheggio gratis. 2 giorni euro 199 a
persona
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid978&d)-12