How to implement a schedule of recurring events?

Hello,

I am fairly new to Ruby and Ruby on Rails. I am creating an application that "has many :groups", each with their own schedule of events. This is a little different than a calendar of events, since these events recur every week and do not have a specific date. So for example, I need to display a schedule for one group that looks like this:

Group A's Activities - Monday at 4pm - Football - Tues/Thurs at 8am - Tennis

I also need to create a form that allows someone to enter new or update existing activities.

I am having a hard time wrapping my brain around how to implement a system like this, and I can't seem to find any gems that do this already.

Can you provide some advice as to how to implement a system like this?

Thanks!

Take a look: https://github.com/jmettraux/rufus-scheduler

the whenever gem is also me! take a look into github

Take a look:GitHub - jmettraux/rufus-scheduler: scheduler for Ruby (at, in, cron and every jobs)

Thanks, but I don't think that gem will help me any:

"rufus-scheduler is a Ruby gem for scheduling pieces of code (jobs)"

I'm trying to display a schedule of events, not schedule a script to be run.

the whenever gem is also me! take a look into github

"Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs."

Like I said before, I am not trying to schedule a cron job, I am trying to display a schedule of events.

I believe you’re looking for temporal expressions. There are a few gems out there that do that kind of thing. I believe it’ll just come down to which API you like best:

http://rubygems.org/gems/temporals

http://texp.rubyforge.org/

http://runt.rubyforge.org/

You can combine Runt with Chronic if you want:

http://townx.org/blog/elliot/ruby_temporal_expressions

For more information, you can just google “ruby temporal expressions”, plenty of information out there.

Hope this helps.

Best regards

Peter De Berdt

I had a lot of success on my second Rails job with this one: https://github.com/bigtiger/event_calendar I used it to build a training calendar for a multi-tenant medical practice system. It worked really well, and was fairly simple for me to modify to my needs.

Events are owned by some other model, so each model can have its own events. I used that feature to show one calendar for each practice, which sounds like it might fit your bill. It has a table-based calendar layout, and handles multi-day events and partial-day events very neatly (in terms of the HTML). The only thing it lacks is a little "blog-style" mini-calendar with highlighted days.

Walter

I had a lot of success on my second Rails job with this one:GitHub - bigtiger/event_calendar: Show multiple, overlapping events across calendar days and rows. Rails plugin.

Thanks for the suggestion. I think I've looked at that one already. Unfortunately, a lot of the libraries/gems that I've found are more like event "calendars" than event "schedules". The problem is that the same schedule of activities occurs every week, so the calendar view would not be very useful since every week would look the same, repeating itself into eternity.

If anybody knows of a gem that displays schedules or has done this sort of thing before, let me know.

Thanks, Andrew

I believe you're looking for temporal expressions.

I believe that I am, too. I came across Runt and that lead me to the article written by Martin Fowler about Temporal Expressions. Definitely a step in the right direction. However, I still can't wrap my mind around how to create a form that I can use to create these temporal expressions, then how to convert the temporal expressions into a schedule layout.

Any advice?

Thanks, Andrew

I believe you’re looking for temporal expressions.

I believe that I am, too. I came across Runt and that lead me to the article written by Martin Fowler about Temporal Expressions.

Would be nice if you could include my original message the next time, it’s easier for me to remember what I posted instead of having to search my mail for the original reply :slight_smile:

Definitely a step in the right direction. However, I still can’t wrap my mind around how to create a form that I can use to create these temporal expressions,

It all depends on the complexity of your recurring events really. I’d suggest starting off by building a form that incorporates the schedule parameters you want to convert into a Runt expression. You could use something like what Google Calendar does, which is pretty basic, or you can go full out complex with multiple combined expressions etc.

Your biggest challenge after that will be to convert the parameters that come into your controller into a Runt expression. I’d suggest writing a dedicated class for that, something like

class RuntExpressionBuilder

def initialize(params)

    # code goes here

end

end

Runt has some nice docs on how to create expressions at http://runt.rubyforge.org/doc/files/doc/tutorial_te_rdoc.html

Not much I can do to help you here, you’ll just need to bite the bullet and write something that works for you based on what the docs provide.

then how to convert the temporal expressions into a schedule layout.

Once you have your expression, you can ask it to give you all the dates in a certain range that comply with your expression:

require ‘runt’

require ‘date’

include Runt

mon_wed_fri = DIWeek.new(Mon) | DIWeek.new(Wed) | DIWeek.new(Fri)

schedule = mon_wed_fri.dates(DateRange.new(PDate.day(2011,7,7),PDate.day(2011,7,20)))

puts schedule

2011-07-08T00:00:00+00:00

2011-07-11T00:00:00+00:00

2011-07-13T00:00:00+00:00

2011-07-15T00:00:00+00:00

2011-07-18T00:00:00+00:00

2011-07-20T00:00:00+00:00

It’ll be up to you to determine how you want to display that schedule to the user of course. You can generate some kind of calendar like has been suggested or keep it plain and simple with a list. It all depends on your application I guess.

Best regards

Peter De Berdt