Holidays can be defined as belonging to one or more regions and sub regions. The Holidays#on, Holidays#between, Date#holidays and Date#holiday? methods each allow you to specify a specific region.
There are several different ways that you can specify a region:
You can load all the available holiday definition sets by running
Holidays.load_all
Return all holidays in the :ca and :us regions on the day that they are observed.
Holidays.between(from, to, :ca, :us, :observed)
Return all holidays in :ca and any :ca sub-region.
Holidays.between(from, to, :ca_)
Return all holidays in :ca_bc sub-region (which includes the :ca), including informal holidays.
Holidays.between(from, to, :ca_bc, :informal)
VERSION | = | '1.0.5' |
WEEKS | = | {:first => 1, :second => 2, :third => 3, :fourth => 4, :fifth => 5, :last => -1, :second_last => -2, :third_last => -3} |
MONTH_LENGTHS | = | [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] |
DAY_SYMBOLS | = | Date::DAYNAMES.collect { |n| n.downcase.intern } |
DEFINITION_PATH | = | File.expand_path(File.dirname(__FILE__) + '/holidays/') |
Returns an array of symbols all the available holiday definitions.
Optional `full_path` param is used internally for loading all the definitions.
Get all holidays occuring between two dates, inclusively.
Returns an array of hashes or nil.
Each holiday is returned as a hash with the following fields:
from = Date.civil(2008,7,1) to = Date.civil(2008,7,31) Holidays.between(from, to, :ca, :us) => [{:name => 'Canada Day', :regions => [:ca]...} {:name => 'Independence Day'', :regions => [:us], ...}]
Get the date of Easter Sunday in a given year. From Easter Sunday, it is possible to calculate many traditional holidays in Western countries. Returns a Date object.
Does the given work-week have any holidays?
The given Date can be any day of the week. Returns true if any holidays fall on Monday - Friday of the given week.
Get all holidays on a given date.
Returns an array of hashes or nil. See Holidays#between for the output format.
Also available via Date#holidays.
Move date to Monday if it occurs on a Sunday. Used as a callback function.
Move Boxing Day if it falls on a weekend, leaving room for Christmas. Used as a callback function.