From: Jeremy McAnally Date: 2007-01-03T01:56:04+09:00 Subject: Re: Detecting holidays Try this: class Date def is_national_holiday? this_year = self.year.to_s # Not perfect; Thanksgiving and Easter change... dates = [this_year + '-12-25', this_year + '-12-24', this_year + '-1-1', this_year + '-7-4', this_year + '-11-28'] if (dates.include?(self.to_s)): return true else return false end end end irb(main):263:0> christmas = Date.parse('2007-12-25') => # irb(main):264:0> christmas.is_national_holiday? => true irb(main):265:0> today = Date.today => # irb(main):266:0> today.is_national_holiday? => false Again, it doesn't get Thanksgiving right or others that change like Easter. If you want, I could hack it in; otherwise, this should get you on the right path. ;) --Jeremy On 1/2/07, Daniel Berger wrote: > Hi all, > > Well, it took seven years, but I've finally been annoyed enough by > reports failing on national holidays to say something. Report writers > know the routine: > > Them: Why did the report fail for Jan. 1st? > Me: National holiday. There was no data to grab. Ignore the failure. > Them: Oh, right. > > Repeat again for Memorial Day, July 4th, Thanksgiving, and Christmas. > > Is there a package out there that deals with national holidays (for any > nation)? The only thing I came across what date2, but that only seems > to handle Japanese national holidays. I guess I'm looking for > something like Perl's Date::Calc [1] module or, more specifically, it's > Date::Calendar::Profiles [2] module. Or something like Perl's > Date::Holidays::XXX [3] approach (I'm not sure which is preferred these > days). > > Ideally, I'd like to be able to do something like: > > if Date.today.is_national_holiday? > exit # Don't run report on this day > end > > And no, it's not a simple matter of using something more flexible than > cron because some reports pull data from X days back or ahead, not on > the date they're run. > > Thoughts? > > - Dan > > [1] http://search.cpan.org/~stbey/Date-Calc-5.4/Calendar.pod > [2] > http://search.cpan.org/~stbey/Date-Calc-5.4/lib/Date/Calendar/Profiles.pod > [3] > http://search.cpan.org/~jonasbn/Date-Holidays-0.08/lib/Date/Holidays.pm > > > -- My free Ruby e-book: http://www.humblelittlerubybook.com/book/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.com/