Commercial Calendar Calculations

J

James Herdman

[Note: parts of this message were removed to make it a legal post.]

I'm interested in doing calculations with a commercial calendar. For
example, "Find every 2nd business day of the month for 2008". I'm feeling a
little long on how to approach the topic. Does anyone know of a library I
could leverage for such a thing (the ability to use said library in Rails is
a must)? If not, does anyone have experience that they could share on the
matter?

Many thanks,

James H.
 
D

Donald Ball

I'm interested in doing calculations with a commercial calendar. For
example, "Find every 2nd business day of the month for 2008". I'm feeling a
little long on how to approach the topic. Does anyone know of a library I
could leverage for such a thing (the ability to use said library in Rails is
a must)? If not, does anyone have experience that they could share on the
matter?

The runt gem provides a nice library for working with recurring
events, it's probably got what you're looking for.

Personally, I looked at runt for an event calendar I built sometime
last year, but it didn't end up being useful as I needed to be able to
store the events in a relational database and query for matching
events therein. To use runt, I'd have had to hydrate all of the events
whenever I wanted to run a query. That was too slow for my use case,
so I ended up doing it all in sql. I'll be happy to share the details
of that implementation if you're in a similar boat.

- donald
 
E

Eric I.

I'm interested in doing calculations with a commercial calendar.  For
example, "Find every 2nd business day of the month for 2008".  I'm feeling a
little long on how to approach the topic.  Does anyone know of a libraryI
could leverage for such a thing (the ability to use said library in Rails is
a must)?  If not, does anyone have experience that they could share on the
matter?

When you say "2nd business day", do you mean logic like, "the 2nd of
the month if it's Tuesday-Friday or the first Monday of the month
otherwise"? Or do you want to take into account a list of holidays
that might make certain weekdays not count as business days?

If it's the former, you could use the Date class (in the 'date'
library). I don't know of a library that handles issues such as
holidays; have you've combed through rubyforge.org?

Eric

====

LearnRuby.com offers Rails & Ruby HANDS-ON public & ON-SITE
workshops.
Ruby Fundamentals Wkshp June 16-18 Ann Arbor, Mich.
Ready for Rails Ruby Wkshp June 23-24 Ann Arbor, Mich.
Ruby on Rails Wkshp June 25-27 Ann Arbor, Mich.
Ruby Plus Rails Combo Wkshp June 23-27 Ann Arbor, Mich
Please visit http://LearnRuby.com for all the details.
 
J

James Herdman

[Note: parts of this message were removed to make it a legal post.]

Donald,
I'm definitely interested in hearing about the details. I'll be having to
deal with an RDBMS as well.

James
 
J

James Herdman

[Note: parts of this message were removed to make it a legal post.]

Eric,
Both. So, if you ask the program to schedule "every first Friday of the
month", if Friday is a holiday, the program should schedule a Thursday
(likewise, if you say "every last day of the month", if the last day is a
holiday, the first business day prior would be scheduled).

It's quite a complicated situation. I thought Runt (as Donald mentioned)
might help, but I'm not sure it will.

James
 
B

`brad`

you could try something like this......very rough pseudo code, but the
logic should be there

def checkworkday(datechecked)
day = datechecked
while day == holiday && day == dayoff
day = nextday
end
return day;
end

dayneeded=firstdayofmonth
nomberofworkdays.times {dayneeded = checkworkday(dayneeded)}
xdayofworkthismonth = dayneeded
 
D

Donald Ball

Donald,
I'm definitely interested in hearing about the details. I'll be having to
deal with an RDBMS as well.

Sure thing, I'll describe briefly here and you can feel free to email
me if you have further questions. My data model included a table of
events, a table of occurrences for events on specific dates, and a
table of recurrences for events that recur. The recurrences table has
columns for event id, weekday, monthweek, and monthday; an event
occurring on all Mondays would have 1 for weekday and null for the
others, while an event occurring on the last Friday of a month would
have 5 for the weekday and -1 for the monthweek. I created a view
joining these data (events, occurrences, recurrences) against a table
of dates, excluding holidays, and end up with a virtual table
consisting of a row for every valid event-date pair.

Given that the date functions in SQL aren't standardized, I'd thought
this would have been practically difficult to bundle up as a rails
plugin, but it now occurs to me that I could store the date parts
(e.g. weekday) in the table of dates, eliminating the need for any
date functions in the database. I may give that a whirl this weekend.

- donald
 
J

James Herdman

[Note: parts of this message were removed to make it a legal post.]

Oh, I see! So if you wanted to get the Date object corresponding to a row
you'd just dump those values into Date.civil. Smart!

I'm curious about your occurrences table. I think I understand this to be
one-time-only events. Is that correct?

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top