From: Axel Etzold Date: 2008-07-19T20:18:38+09:00 Subject: Re: Finding the date of an event based on related events. -------- Original-Nachricht -------- > Datum: Sat, 19 Jul 2008 01:20:12 +0900 > Von: Kaldrenon > An: ruby-talk@ruby-lang.org > Betreff: Finding the date of an event based on related events. > 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? I know that with Ruby's Date class you can > use the - (minus) operator to subtract x days from the date of an > existing event. which is how I can find the exact date once I've > determined the number of total days it will be before it has been x > business days. > > But the "human" solution to the problem isn't very efficient - > iterating over the days with a counter, checking Date.wday, ignoring > days that return 0 and 6, and spitting back the date at which the > counter reaches x. I'd like to find a more elegant and computationally > efficient solution. > > If you've worked out this problem before, or a better solution seems > readily available to you, I'd love input. If my explanation was > unclear, I'll gladly clarify anything. > > -Andrew Fallows Dear Andrew, reading previous responses to your post, I'd like to mention that you can get a list of public holidays from the Wikipedia http://en.wikipedia.org/wiki/List_of_holidays_by_country, for many countries, the movable holidays are mostly Easter and Pentecost, there is a listing of the Easter dates here (and Pentecost is, I believe, just 7 weeks later): http://www.assa.org.au/edm.html#List20 and, secondly, that for the main task you have -- scheduling --- you could use a "Constraint Programming" framework, such as this: http://gecoder.rubyforge.org/ where you input all the conditions you have and get back a solution... Best regards, Axel -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal f�r Modem und ISDN: http://www.gmx.net/de/go/smartsurfer