Class Date
In: lib/holidays.rb
Parent: Object

Extending Ruby‘s Date class with the Holidays gem

The Holidays gem automatically extends Ruby‘s Date class and gives you access to three new methods: holiday?, holidays and calculate_mday.

Examples

Lookup Canada Day in the :ca region

  Date.civil(2008,7,1).holiday?(:ca)
  => true

Lookup Canada Day in the :fr region

  Date.civil(2008,7,1).holiday?(:fr)
  => false

Lookup holidays on North America in January 1.

  Date.civil(2008,1,1).holidays(:ca, :mx, :us, :informal, :observed)
  => [{:name => 'New Year\'s Day'...}]

Methods

Included Modules

Holidays

Public Class methods

Calculate day of the month based on the week number and the day of the week.

Parameters

year
Integer.
month
Integer from 1-12.
week
One of :first, :second, :third, :fourth, :fifth or :last.
wday
Day of the week as an integer from 0 (Sunday) to 6 (Saturday) or as a symbol (e.g. :monday).

Returns an integer.

Examples

First Monday of January, 2008:

  Date.calculate_mday(2008, 1, :first, :monday)
  => 7

Third Thursday of December, 2008:

  Date.calculate_mday(2008, 12, :third, :thursday)
  => 18

Last Monday of January, 2008:

  Date.calculate_mday(2008, 1, :last, 1)
  => 28

Public Instance methods

Check if the current date is a holiday.

Returns true or false.

  Date.civil('2008-01-01').holiday?(:ca)
  => true

Get holidays on the current date.

Returns an array of hashes or nil. See Holidays#between for options and the output format.

  Date.civil('2008-01-01').holidays(:ca_)
  => [{:name => 'New Year\'s Day',...}]

Also available via Holidays#on.

[Validate]