Mat Schaffer
1/2/2007 6:59:00 PM
On Jan 2, 2007, at 11:56 AM, Jeremy McAnally wrote:
> 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')
> => #<Date: 4908919/2,0,2299161>
> irb(main):264:0> christmas.is_national_holiday?
> => true
> irb(main):265:0> today = Date.today
> => #<Date: 4908205/2,0,2299161>
> 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. ;)
For those sort of holidays you could use the Chronic gem to parse a
textual date:
irb(main):010:0> Chronic.parse('4th thursday in november')
=> Thu Nov 22 11:00:00 -0500 2007
Still kind of a shame there isn't just a 'holidays' gem.
-Mat