From: Daniel Berger Date: 2007-01-03T06:00:05+09:00 Subject: Re: Detecting holidays Mat Schaffer wrote: > On Jan 2, 2007, at 2:55 PM, Daniel Berger wrote: > > Jeremy McAnally wrote: > >> Well, the way I'm working it out is like AR's dynamic finders. It > >> will have a few groups of dates hardcoded (like national holidays and > >> such), but then you can give it new groups in the form hashes of > >> arrays of dates with named "work_holidays" or "surprise_offdays" and > >> then call the method like is_a_work_holiday? or > >> is_a_surprise_offday?. > >> I'm still working on it...I'll post when I've got it done. > > > > Actually, once I took a stab at it, I think it's fairly easy for the > > national holidays IF I'm using Date#cweek correctly and reliably here: > > > > require 'date' > > > > class Date > > def thanksgiving? > > month == 11 && wday == 4 && cweek == 3 > > end > > I think it would be cweek == 4, but I like the idea. This particular > implementation doesn't seem very extensible. Not sure what would be > the best way to define some sort of custom holidays file that could > be read by a gem... Procs in a hash comes to mind. Yeah, I think you're right about the cweek. You're also right about this implementation not being very extensible. On a side note, I was thinking of something like this for a theoretical layout: lib/ date/ holiday/ us.rb uk.rb jp.rb ... And then the end user would simply do "require 'date/holiday/us'" to get the US holidays, etc. I'm not certain, though. Regards, Dan PS - The Date#national_holiday? method I posted is wrong. There should be "||" not "&&" between the method checks.