holidays/test/fixtures/ca.rb

83 lines
3.4 KiB
Ruby
Raw Normal View History

# This file is generated by the Ruby Holiday gem.
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/testmodule'
#
# More definitions are available at http://code.dunae.ca/holidays.
#
# Definitions loaded: data/ca.yaml
module Holidays
module TestModule
DEFINED_REGIONS = [:ca]
HOLIDAYS_BY_MONTH = {
5 => [{:function => lambda { |year| ca_victoria_day(year) }, :name => "Victoria Day", :regions => [:ca]},
{:function => lambda { |year| ca_victoria_day(year) }, :name => "National Patriotes Day", :regions => [:ca_qc]}],
0 => [{:function => lambda { |year| easter(year)-2 }, :name => "Good Friday", :regions => [:ca]},
{:function => lambda { |year| easter(year)+1 }, :name => "Easter Monday", :regions => [:ca_qc]}],
11 => [{:mday => 11, :name => "Rememberance Day", :regions => [:ca]}],
6 => [{:mday => 24, :name => "Discovery Day", :regions => [:ca_nf]},
{:mday => 24, :name => "F<EFBFBD>te Nationale", :regions => [:ca_qc]},
{:mday => 21, :name => "National Aboriginal Day", :regions => [:ca_nt]}],
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:ca]},
{:mday => 2, :name => "New Year's", :regions => [:ca_qc]}],
12 => [{:mday => 25, :name => "Christmas Day", :regions => [:ca]},
{:mday => 26, :name => "Boxing Day", :regions => [:ca]}],
7 => [{:mday => 1, :name => "Canada Day", :regions => [:ca]},
{:mday => 12, :name => "Orangemen's Day", :regions => [:ca]},
{:mday => 9, :name => "Nunavut Day", :regions => [:ca_nu]}],
2 => [{:wday => 1, :week => 3, :name => "Family Day", :regions => [:ca_ab, :ca_on, :ca_sk]},
{:wday => 1, :week => 3, :name => "Louis Riel Day", :regions => [:ca_mb]}],
8 => [{:wday => 1, :week => 1, :name => "BC Day", :regions => [:ca_bc]},
{:wday => 1, :week => 1, :name => "Saskatchewan Day", :regions => [:ca_sk]},
{:wday => 1, :week => 1, :name => "Heritage Day", :regions => [:ca_ab]},
{:wday => 1, :week => 1, :name => "Natal Day", :regions => [:ca_ns]},
{:wday => 1, :week => 1, :name => "Civic Holiday", :regions => [:ca_on]},
{:wday => 1, :week => 3, :name => "Discovery Day", :regions => [:ca_yk]}],
3 => [{:mday => 23, :name => "St. George's Day", :regions => [:ca_nf]}],
9 => [{:wday => 1, :week => 1, :name => "Labour Day", :regions => [:ca]}],
10 => [{:wday => 1, :week => 2, :name => "Thanksgiving", :regions => [:ca]}]
}
def self.easter(year)
Date.civil(2008,1,1)
end
# Monday on or before May 24
def self.ca_victoria_day(year)
date = Date.civil(year,5,24)
if date.wday > 1
date -= (date.wday - 1)
elsif date.wday == 0
date -= 6
end
date
end
end
end
Holidays.class_eval do
existing_regions = []
if const_defined?(:DEFINED_REGIONS)
existing_regions = const_get(:DEFINED_REGIONS)
remove_const(:DEFINED_REGIONS)
end
const_set(:DEFINED_REGIONS, existing_regions | Holidays::TestModule::DEFINED_REGIONS)
existing_defs = {}
if const_defined?(:HOLIDAYS_BY_MONTH)
existing_defs = const_get(:HOLIDAYS_BY_MONTH)
remove_const(:HOLIDAYS_BY_MONTH)
end
#const_set(:HOLIDAYS_BY_MONTH, existing_defs.merge(Holidays::TestModule::HOLIDAYS_BY_MONTH))
const_set(:HOLIDAYS_BY_MONTH, Holidays::TestModule::HOLIDAYS_BY_MONTH)
include Holidays::TestModule
end