Added Boxing Day method and GB, US and CA observed holidays
This commit is contained in:
parent
49f6883938
commit
59f5d2e91c
11 changed files with 51 additions and 28 deletions
|
@ -70,6 +70,7 @@ def parse_holiday_defs(module_name, files)
|
|||
|
||||
if rule['observed']
|
||||
str << ":observed => lambda { |date| Holidays.#{rule['observed']}(date) }, "
|
||||
str << ":observed_id => \"#{rule['observed'].to_s}\", "
|
||||
end
|
||||
|
||||
if rule['type']
|
||||
|
|
|
@ -73,7 +73,8 @@ months:
|
|||
- name: Christmas Day
|
||||
regions: [gb]
|
||||
mday: 25
|
||||
observed: to_monday_if_weekend
|
||||
- name: Boxing Day
|
||||
regions: [gb]
|
||||
mday: 26
|
||||
|
||||
observed: to_weekday_if_boxing_weekend
|
||||
|
|
|
@ -90,6 +90,7 @@ module Holidays
|
|||
next unless hbm = @@holidays_by_month[month]
|
||||
hbm.each do |h|
|
||||
next unless in_region?(regions, h[:regions])
|
||||
|
||||
next if h[:type] == :informal and not informal
|
||||
|
||||
if h[:function]
|
||||
|
@ -104,6 +105,7 @@ module Holidays
|
|||
mday = h[:mday] || Date.calculate_mday(year, month, h[:week], h[:wday])
|
||||
end
|
||||
|
||||
|
||||
begin
|
||||
date = Date.new(year, month, mday)
|
||||
rescue; next; end
|
||||
|
@ -114,6 +116,7 @@ module Holidays
|
|||
date = call_proc(h[:observed], date)
|
||||
end
|
||||
|
||||
|
||||
if date.between?(start_date, end_date)
|
||||
holidays << {:date => date, :name => h[:name], :regions => h[:regions]}
|
||||
end
|
||||
|
@ -139,9 +142,7 @@ module Holidays
|
|||
|
||||
exists = false
|
||||
@@holidays_by_month[month].each do |ex|
|
||||
|
||||
if ex[:name] == holiday_def[:name] and ex[:wday] == holiday_def[:wday] and ex[:mday] == holiday_def[:mday] and ex[:week] == holiday_def[:week] and ex[:function_id] == holiday_def[:function_id] and ex[:type] == holiday_def[:type]
|
||||
|
||||
if ex[:name] == holiday_def[:name] and ex[:wday] == holiday_def[:wday] and ex[:mday] == holiday_def[:mday] and ex[:week] == holiday_def[:week] and ex[:function_id] == holiday_def[:function_id] and ex[:type] == holiday_def[:type] and ex[:observed_id] == holiday_def[:observed_id]
|
||||
# append regions
|
||||
ex[:regions] << holiday_def[:regions]
|
||||
|
||||
|
@ -198,6 +199,21 @@ module Holidays
|
|||
date
|
||||
end
|
||||
|
||||
# Move date to Monday if it occurs on a Saturday on Sunday.
|
||||
# Used as a callback function.
|
||||
def self.to_monday_if_weekend(date)
|
||||
date += 1 if date.wday == 0
|
||||
date += 2 if date.wday == 6
|
||||
date
|
||||
end
|
||||
|
||||
# Move Boxing Day if it falls on a weekend, leaving room for Christmas.
|
||||
# Used as a callback function.
|
||||
def self.to_weekday_if_boxing_weekend(date)
|
||||
date += 2 if date.wday == 6 or date.wday == 0
|
||||
date
|
||||
end
|
||||
|
||||
# Move date to Monday if it occurs on a Sunday or to Friday if it occurs on a
|
||||
# Saturday.
|
||||
# Used as a callback function.
|
||||
|
|
|
@ -27,7 +27,7 @@ module Holidays
|
|||
{: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, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :name => "Canada Day", :regions => [:ca]},
|
||||
7 => [{:mday => 1, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Canada Day", :regions => [:ca]},
|
||||
{:mday => 12, :name => "Orangemen's Day", :regions => [:ca_nf]},
|
||||
{:mday => 9, :name => "Nunavut Day", :regions => [:ca_nu]}],
|
||||
2 => [{:wday => 1, :week => 3, :name => "Family Day", :regions => [:ca_ab, :ca_on, :ca_sk]},
|
||||
|
|
|
@ -134,8 +134,9 @@ module Holidays
|
|||
{:mday => 25, :name => "Navidad del Señor", :regions => [:es]},
|
||||
{:mday => 26, :name => "San Esteban", :regions => [:es_ib, :es_ct]},
|
||||
{:mday => 25, :name => "Nöel", :regions => [:fr]},
|
||||
{:mday => 25, :name => "Christmas Day", :regions => [:gb, :ie]},
|
||||
{:mday => 26, :name => "Boxing Day", :regions => [:gb]},
|
||||
{:mday => 25, :observed => lambda { |date| Holidays.to_monday_if_weekend(date) }, :observed_id => "to_monday_if_weekend", :name => "Christmas Day", :regions => [:gb]},
|
||||
{:mday => 26, :observed => lambda { |date| Holidays.to_weekday_if_boxing_weekend(date) }, :observed_id => "to_weekday_if_boxing_weekend", :name => "Boxing Day", :regions => [:gb]},
|
||||
{:mday => 25, :name => "Christmas Day", :regions => [:ie]},
|
||||
{:mday => 26, :name => "St. Stephen's Day", :regions => [:ie]},
|
||||
{:mday => 24, :name => "Jól", :regions => [:is]},
|
||||
{:mday => 25, :name => "Jól", :regions => [:is]},
|
||||
|
|
|
@ -23,8 +23,8 @@ module Holidays
|
|||
11 => [{:mday => 5, :type => :informal, :name => "Guy Fawkes Day", :regions => [:gb]}],
|
||||
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:gb]},
|
||||
{:mday => 2, :name => "New Year's", :regions => [:gb_sct]}],
|
||||
12 => [{:mday => 25, :name => "Christmas Day", :regions => [:gb]},
|
||||
{:mday => 26, :name => "Boxing Day", :regions => [:gb]}],
|
||||
12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_monday_if_weekend(date) }, :observed_id => "to_monday_if_weekend", :name => "Christmas Day", :regions => [:gb]},
|
||||
{:mday => 26, :observed => lambda { |date| Holidays.to_weekday_if_boxing_weekend(date) }, :observed_id => "to_weekday_if_boxing_weekend", :name => "Boxing Day", :regions => [:gb]}],
|
||||
7 => [{:mday => 5, :name => "Tynwald Day", :regions => [:im, :gb_iom]},
|
||||
{:mday => 12, :name => "Battle of the Boyne", :regions => [:gb_nir]}],
|
||||
8 => [{:wday => 1, :week => 1, :name => "Bank Holiday", :regions => [:gb_sct]},
|
||||
|
|
|
@ -30,7 +30,7 @@ module Holidays
|
|||
{:mday => 1, :type => :informal, :name => "Todos los Santos", :regions => [:mx]},
|
||||
{:mday => 2, :type => :informal, :name => "Los Fieles Difuntos", :regions => [:mx]},
|
||||
{:wday => 1, :week => 3, :name => "Día de la Revolución", :regions => [:mx]},
|
||||
{:mday => 11, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "Veterans Day", :regions => [:us]},
|
||||
{:mday => 11, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Veterans Day", :regions => [:us]},
|
||||
{:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:us]}],
|
||||
6 => [{:mday => 24, :name => "Discovery Day", :regions => [:ca_nf]},
|
||||
{:mday => 24, :name => "Fête Nationale", :regions => [:ca_qc]},
|
||||
|
@ -40,7 +40,7 @@ module Holidays
|
|||
{:mday => 2, :name => "New Year's", :regions => [:ca_qc]},
|
||||
{:mday => 1, :name => "Año nuevo", :regions => [:mx]},
|
||||
{:mday => 6, :name => "Dia de los Santos Reyes", :regions => [:mx]},
|
||||
{:mday => 1, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "New Year's Day", :regions => [:us]},
|
||||
{:mday => 1, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "New Year's Day", :regions => [:us]},
|
||||
{:wday => 1, :week => 3, :name => "Martin Luther King, Jr. Day", :regions => [:us]},
|
||||
{:function => lambda { |year| Holidays.us_inauguration_day(year) }, :function_id => "us_inauguration_day(year)", :name => "Inauguration Day", :regions => [:us_dc]}],
|
||||
12 => [{:mday => 25, :name => "Christmas Day", :regions => [:ca]},
|
||||
|
@ -49,11 +49,11 @@ module Holidays
|
|||
{:mday => 24, :type => :informal, :name => "Nochebuena", :regions => [:mx]},
|
||||
{:mday => 25, :name => "Navidad", :regions => [:mx]},
|
||||
{:mday => 28, :name => "Los Santos Inocentes", :regions => [:mx]},
|
||||
{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "Christmas Day", :regions => [:us]}],
|
||||
7 => [{:mday => 1, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :name => "Canada Day", :regions => [:ca]},
|
||||
{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Christmas Day", :regions => [:us]}],
|
||||
7 => [{:mday => 1, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Canada Day", :regions => [:ca]},
|
||||
{:mday => 12, :name => "Orangemen's Day", :regions => [:ca_nf]},
|
||||
{:mday => 9, :name => "Nunavut Day", :regions => [:ca_nu]},
|
||||
{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "Independence Day", :regions => [:us]}],
|
||||
{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Independence Day", :regions => [:us]}],
|
||||
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]},
|
||||
{:mday => 2, :type => :informal, :name => "Groundhog Day", :regions => [:us, :ca]},
|
||||
|
|
|
@ -17,13 +17,13 @@ module Holidays
|
|||
5 => [{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:us]},
|
||||
{:wday => 0, :week => 3, :type => :informal, :name => "Father's Day", :regions => [:us, :ca]}],
|
||||
0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :type => :informal, :name => "Good Friday", :regions => [:us]}],
|
||||
11 => [{:mday => 11, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "Veterans Day", :regions => [:us]},
|
||||
11 => [{:mday => 11, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Veterans Day", :regions => [:us]},
|
||||
{:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:us]}],
|
||||
1 => [{:mday => 1, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "New Year's Day", :regions => [:us]},
|
||||
1 => [{:mday => 1, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "New Year's Day", :regions => [:us]},
|
||||
{:wday => 1, :week => 3, :name => "Martin Luther King, Jr. Day", :regions => [:us]},
|
||||
{:function => lambda { |year| Holidays.us_inauguration_day(year) }, :function_id => "us_inauguration_day(year)", :name => "Inauguration Day", :regions => [:us_dc]}],
|
||||
12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "Christmas Day", :regions => [:us]}],
|
||||
7 => [{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "Independence Day", :regions => [:us]}],
|
||||
12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Christmas Day", :regions => [:us]}],
|
||||
7 => [{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Independence Day", :regions => [:us]}],
|
||||
2 => [{:wday => 1, :week => 3, :name => "Presidents' Day", :regions => [:us]},
|
||||
{:mday => 2, :type => :informal, :name => "Groundhog Day", :regions => [:us, :ca]},
|
||||
{:mday => 14, :type => :informal, :name => "Valentine's Day", :regions => [:us, :ca]}],
|
||||
|
|
|
@ -15,14 +15,14 @@ class HolidaysTests < Test::Unit::TestCase
|
|||
h = Holidays.on(Date.civil(2008,9,1), :ca)
|
||||
assert_equal 'Labour Day', h[0][:name]
|
||||
|
||||
holidays = Holidays.on(Date.civil(2008,7,1), :ca)
|
||||
assert_equal 1, holidays.length
|
||||
|
||||
holidays = Holidays.on(Date.civil(2008,7,4), :ca)
|
||||
assert_equal 0, holidays.length
|
||||
end
|
||||
|
||||
def test_between
|
||||
holidays = Holidays.between(Date.civil(2008,7,1), Date.civil(2008,7,1), :ca)
|
||||
assert_equal 1, holidays.length
|
||||
|
||||
holidays = Holidays.between(Date.civil(2008,7,1), Date.civil(2008,7,31), :ca)
|
||||
assert_equal 1, holidays.length
|
||||
|
||||
|
@ -54,7 +54,7 @@ class HolidaysTests < Test::Unit::TestCase
|
|||
|
||||
def test_observed_dates
|
||||
# Should fall on Tuesday the 1st
|
||||
assert_equal 1, Holidays.on(Date.civil(2008,7,1), :ca, :observed).length
|
||||
assert_equal 1, Holidays.on(Date.civil(2008,7,1), :ca, :observed).length
|
||||
|
||||
# Should fall on Monday the 2nd
|
||||
assert_equal 1, Holidays.on(Date.civil(2007,7,2), :ca, :observed).length
|
||||
|
|
|
@ -109,9 +109,10 @@ class RegionTests < Test::Unit::TestCase
|
|||
|
||||
|
||||
def test_gb
|
||||
# Holidays.between(Date.civil(2008,1,1),Date.civil(2008,12,1),:gb_).each do |h|
|
||||
# Holidays.between(Date.civil(2010,12,1),Date.civil(2008,12,31),:gb_).each do |h|
|
||||
# puts "#{h[:name]} on #{h[:date]}"
|
||||
# end
|
||||
|
||||
{Date.civil(2008,1,1) => 'New Year\'s Day',
|
||||
Date.civil(2008,3,21) => 'Good Friday',
|
||||
Date.civil(2008,3,23) => 'Easter Sunday',
|
||||
|
@ -125,6 +126,14 @@ class RegionTests < Test::Unit::TestCase
|
|||
|
||||
assert_equal 'St. Patrick\'s Day', Date.civil(2008,3,17).holidays(:gb_nir, :informal)[0][:name]
|
||||
|
||||
assert_equal 'Christmas Day', Date.civil(2008,12,25).holidays(:gb_, :observed)[0][:name]
|
||||
assert_equal 'Christmas Day', Date.civil(2009,12,25).holidays(:gb_, :observed)[0][:name]
|
||||
assert_equal 'Christmas Day', Date.civil(2010,12,27).holidays(:gb_, :observed)[0][:name]
|
||||
|
||||
assert_equal 'Boxing Day', Date.civil(2008,12,26).holidays(:gb_, :observed)[0][:name]
|
||||
assert_equal 'Boxing Day', Date.civil(2009,12,28).holidays(:gb_, :observed)[0][:name]
|
||||
assert_equal 'Boxing Day', Date.civil(2010,12,28).holidays(:gb_, :observed)[0][:name]
|
||||
|
||||
[:gb_wls, :gb_eng, :gb_nir, :gb_eaw, :gb_].each do |r|
|
||||
assert_equal 'Easter Monday', Date.civil(2008,3,24).holidays(r)[0][:name]
|
||||
assert_equal 'Bank Holiday', Date.civil(2008,8,25).holidays(r)[0][:name]
|
||||
|
|
|
@ -23,7 +23,6 @@ class North_AmericaTests < Test::Unit::TestCase
|
|||
Date.civil(2007,5,21), Date.civil(2008,5,19)].each do |date|
|
||||
assert_equal 'Victoria Day', Holidays.on(date, :ca)[0][:name]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# from
|
||||
|
@ -41,8 +40,6 @@ class North_AmericaTests < Test::Unit::TestCase
|
|||
Date.civil(2007,12,25) => 'Navidad'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :mx, :informal)[0][:name]
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def test_us
|
||||
|
@ -59,7 +56,5 @@ class North_AmericaTests < Test::Unit::TestCase
|
|||
assert_equal name, Holidays.on(date, :us)[0][:name]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue