From: Siep Korteling Date: 2008-07-19T07:04:08+09:00 Subject: Re: Finding the date of an event based on related events. Kaldrenon wrote: > Hi all, > > I'm doing some planning to write a simple utility program for > maintaining my schedule. The basic scenario is that, in my job, I have > a series of multi-stage procedures to perform, and for each instance > of the procedure, the stages need to happen a fixed number of business > days apart (i.e, if step one happens on Monday, step two is Friday, > but if step one is Tuesday, step two will be the following Monday). As > one of the first steps of the program, I'm going to write a script to > quickly spit out the calendar dates of all steps given the date of the > first and the relative date (in business days) of all the others. > > My question is, can you help me drum up a 'smart' way to take weekends > and holidays into account? (...) > > -Andrew Fallows To exclude just the weekends you could do class Date def add_workdays(n) days_to_add =((self.cwday+n-1)/5)*2 +n self + days_to_add end end Which returns a new Date and seems to work with negative n's. (Just wrote this code, don't know if it's bullet proof). Holidays are a complication.Ideally the solution would allow for different holidays for different countries. Working hours could be specified, to enable calculating exactly when a 14 hour job starting on friday 24 december 15:15 in the US would finish. Two applications I work with have these features. I'm not aware of a ruby solution/gem. Regards, Siep -- Posted via http://www.ruby-forum.com/.