Added support for informal and observed holidays
This commit is contained in:
parent
6cb7ccd148
commit
49f6883938
10 changed files with 143 additions and 76 deletions
|
@ -30,13 +30,9 @@ def parse_holiday_defs(module_name, files)
|
|||
|
||||
exists = false
|
||||
rules_by_month[month].each do |ex|
|
||||
if ex['name'] == rule['name'] and ex['wday'] == rule['wday'] and ex['mday'] == rule['mday'] and ex['week'] == rule['week'] and ex['function'] == rule['function']
|
||||
if ex['name'] == rule['name'] and ex['wday'] == rule['wday'] and ex['mday'] == rule['mday'] and ex['week'] == rule['week'] and ex['type'] == rule['type'] and ex['function'] == rule['function'] and ex['observed'] == rule['observed']
|
||||
ex['regions'] << rule['regions'].flatten
|
||||
exists = true
|
||||
else
|
||||
if rule['function_id']
|
||||
"Rejecting #{rule['function_id']}"
|
||||
end
|
||||
end
|
||||
end
|
||||
unless exists
|
||||
|
@ -72,6 +68,10 @@ def parse_holiday_defs(module_name, files)
|
|||
str << ":wday => #{rule['wday']}, :week => #{rule['week']}, "
|
||||
end
|
||||
|
||||
if rule['observed']
|
||||
str << ":observed => lambda { |date| Holidays.#{rule['observed']}(date) }, "
|
||||
end
|
||||
|
||||
if rule['type']
|
||||
str << ":type => :#{rule['type']}, "
|
||||
end
|
||||
|
|
|
@ -55,6 +55,7 @@ months:
|
|||
- name: Canada Day
|
||||
regions: [ca]
|
||||
mday: 1
|
||||
observed: to_monday_if_sunday
|
||||
- name: Orangemen's Day
|
||||
regions: [ca_nf]
|
||||
mday: 12
|
||||
|
|
|
@ -13,6 +13,7 @@ months:
|
|||
- name: New Year's Day
|
||||
regions: [us]
|
||||
mday: 1
|
||||
observed: to_weekday_if_weekend
|
||||
- name: Martin Luther King, Jr. Day
|
||||
week: 3
|
||||
regions: [us]
|
||||
|
@ -34,6 +35,7 @@ months:
|
|||
- name: Independence Day
|
||||
regions: [us]
|
||||
mday: 4
|
||||
observed: to_weekday_if_weekend
|
||||
9:
|
||||
- name: Labor Day
|
||||
week: 1
|
||||
|
@ -48,6 +50,7 @@ months:
|
|||
- name: Veterans Day
|
||||
regions: [us]
|
||||
mday: 11
|
||||
observed: to_weekday_if_weekend
|
||||
- name: Thanksgiving
|
||||
week: 4
|
||||
regions: [us]
|
||||
|
@ -56,6 +59,7 @@ months:
|
|||
- name: Christmas Day
|
||||
regions: [us]
|
||||
mday: 25
|
||||
observed: to_weekday_if_weekend
|
||||
methods:
|
||||
us_inauguration_day: |
|
||||
# January 20, every fourth year, following Presidential election
|
||||
|
|
111
lib/holidays.rb
111
lib/holidays.rb
|
@ -4,18 +4,41 @@ require 'digest/md5'
|
|||
|
||||
# === Ruby Holidays module
|
||||
#
|
||||
# ==== Using regions
|
||||
# ==== Region options
|
||||
# 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:
|
||||
#
|
||||
# ca:: By region. Return holidays in the CA region (Canada).
|
||||
# ca_:: By region and sub regions. Return holidays in the CA region and all sub regions.
|
||||
# [<tt>:region</tt>]
|
||||
# By region. For example, return holidays in the Canada with <tt>:ca</tt>.
|
||||
# [<tt>:region_</tt>]
|
||||
# By region and sub regions. For example, return holidays in Germany
|
||||
# and all its sub regions with <tt>:de_</tt>.
|
||||
# [<tt>:region_sub</tt>]
|
||||
# By sub region. Return national holidays in Spain plus holidays in Spain's
|
||||
# Valencia region with <tt>:es_v</tt>.
|
||||
# [<tt>:any</tt>]
|
||||
# Any region. Return holidays from any loaded region.
|
||||
#
|
||||
# ca_bc:: By sub region. Return holidays in the CA region and CA_BC sub region.
|
||||
# any:: Any region. Return holidays from any region.
|
||||
# ==== Other options
|
||||
# [<tt>:observed</tt>] Return holidays on the day they are observed (e.g. on a Monday if they fall on a Sunday).
|
||||
# [<tt>:informal</tt>] Include informal holidays (e.g. Valentine's Day)
|
||||
#
|
||||
# ==== Examples
|
||||
# Return all holidays in the <tt>:ca</tt> and <tt>:us</tt> regions on the day that they are
|
||||
# observed.
|
||||
#
|
||||
# Holidays.between(from, to, :ca, :us, :observed)
|
||||
#
|
||||
# Return all holidays in <tt>:ca</tt> and any <tt>:ca</tt> sub-region.
|
||||
#
|
||||
# Holidays.between(from, to, :ca_)
|
||||
#
|
||||
# Return all holidays in <tt>:ca_bc</tt> sub-region (which includes the <tt>:ca</tt>), including informal holidays.
|
||||
#
|
||||
# Holidays.between(from, to, :ca_bc, :informal)
|
||||
module Holidays
|
||||
# Exception thrown when an unknown region is requested.
|
||||
class UnkownRegionError < ArgumentError; end
|
||||
|
@ -29,22 +52,17 @@ module Holidays
|
|||
WEEKS = {:first => 1, :second => 2, :third => 3, :fourth => 4, :fifth => 5, :last => -1}
|
||||
MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
||||
|
||||
#--
|
||||
#HOLIDAYS_TYPES = [:bank, :statutory, :religious, :informal]
|
||||
#++
|
||||
|
||||
# Get all holidays on a given date.
|
||||
#
|
||||
# [<tt>date</tt>] A Date object.
|
||||
# [<tt>regions</tt>] A symbol (e.g. <tt>:ca</tt>) or an array of symbols
|
||||
# (e.g. <tt>[:ca, :ca_bc, :us]</tt>).
|
||||
# [<tt>date</tt>] A Date object.
|
||||
# [<tt>:options</tt>] One or more region symbols, <tt>:informal</tt> and/or <tt>:observed</tt>.
|
||||
#
|
||||
# Returns an array of hashes or nil. See Holidays#between for the output
|
||||
# format.
|
||||
#
|
||||
# Also available via Date#holidays.
|
||||
def self.on(date, regions = :any)
|
||||
self.between(date, date, regions)
|
||||
def self.on(date, *options)
|
||||
self.between(date, date, options)
|
||||
end
|
||||
|
||||
# Get all holidays occuring between two dates, inclusively.
|
||||
|
@ -54,11 +72,9 @@ module Holidays
|
|||
# Each holiday is returned as a hash with the following fields:
|
||||
# [<tt>:date</tt>] Ruby Date object.
|
||||
# [<tt>:name</tt>] String.
|
||||
# [<tt>:regions</tt>] An array of region symbols.
|
||||
#--
|
||||
# [<tt>:types</tt>] An array of holiday-type symbols.
|
||||
def self.between(start_date, end_date, regions = :any)
|
||||
regions = validate_regions(regions)
|
||||
# [<tt>:options</tt>] One or more region symbols, <tt>:informal</tt> and/or <tt>:observed</tt>.
|
||||
def self.between(start_date, end_date, *options)
|
||||
regions, observed, informal = parse_options(options)
|
||||
holidays = []
|
||||
|
||||
dates = {}
|
||||
|
@ -74,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]
|
||||
result = call_proc(h[:function], year)
|
||||
|
@ -91,6 +108,12 @@ module Holidays
|
|||
date = Date.new(year, month, mday)
|
||||
rescue; next; end
|
||||
|
||||
# If the :observed option is set, calculate the date when the holiday
|
||||
# is observed.
|
||||
if observed and h[:observed]
|
||||
date = call_proc(h[:observed], date)
|
||||
end
|
||||
|
||||
if date.between?(start_date, end_date)
|
||||
holidays << {:date => date, :name => h[:name], :regions => h[:regions]}
|
||||
end
|
||||
|
@ -117,7 +140,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]
|
||||
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]
|
||||
|
||||
# append regions
|
||||
ex[:regions] << holiday_def[:regions]
|
||||
|
@ -126,11 +149,9 @@ module Holidays
|
|||
ex[:regions].flatten!
|
||||
ex[:regions].uniq!
|
||||
exists = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
unless exists
|
||||
@@holidays_by_month[month] << holiday_def
|
||||
if holiday_def[:function]
|
||||
|
@ -170,16 +191,42 @@ module Holidays
|
|||
Date.civil(year, month, day)
|
||||
end
|
||||
|
||||
# Move date to Monday if it occurs on a Sunday.
|
||||
# Used as a callback function.
|
||||
def self.to_monday_if_sunday(date)
|
||||
date += 1 if 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.
|
||||
def self.to_weekday_if_weekend(date)
|
||||
date += 1 if date.wday == 0
|
||||
date -= 1 if date.wday == 6
|
||||
date
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
# Returns [(arr)regions, (bool)observed, (bool)informal]
|
||||
def self.parse_options(*options) # :nodoc:
|
||||
options.flatten!
|
||||
observed = options.delete(:observed) ? true : false
|
||||
informal = options.delete(:informal) ? true : false
|
||||
regions = parse_regions(options)
|
||||
return regions, observed, informal
|
||||
end
|
||||
|
||||
# Check regions against list of supported regions and return an array of
|
||||
# symbols.
|
||||
#
|
||||
# If a wildcard region is found (e.g. <tt>:ca_</tt>) it is expanded into all
|
||||
# of its available sub regions.
|
||||
def self.validate_regions(regions) # :nodoc:
|
||||
def self.parse_regions(regions) # :nodoc:
|
||||
regions = [regions] unless regions.kind_of?(Array)
|
||||
return [:any] if regions.empty?
|
||||
|
||||
regions = regions.collect { |r| r.to_sym }
|
||||
|
||||
# Found sub region wild-card
|
||||
|
@ -267,26 +314,26 @@ class Date
|
|||
|
||||
# Get holidays on the current date.
|
||||
#
|
||||
# Returns an array of hashes or nil. See Holidays#between for the output
|
||||
# format.
|
||||
# Returns an array of hashes or nil. See Holidays#between for options
|
||||
# and the output format.
|
||||
#
|
||||
# Date.civil('2008-01-01').holidays(:ca)
|
||||
# => [{:name => 'Canada Day',...}]
|
||||
#
|
||||
# Also available via Holidays#on.
|
||||
def holidays(regions = :any)
|
||||
Holidays.on(self, regions)
|
||||
def holidays(*options)
|
||||
Holidays.on(self, options)
|
||||
end
|
||||
|
||||
# Check if the current date is a holiday.
|
||||
#
|
||||
# Returns an array of hashes or nil. See Holidays#between for the output
|
||||
# format.
|
||||
# Returns an array of hashes or nil. See Holidays#between for options
|
||||
# and the output format.
|
||||
#
|
||||
# Date.civil('2008-01-01').holiday?(:ca)
|
||||
# => true
|
||||
def holiday?(regions = :any)
|
||||
holidays = self.holidays(regions)
|
||||
def holiday?(*options)
|
||||
holidays = self.holidays(options)
|
||||
holidays && !holidays.empty?
|
||||
end
|
||||
|
||||
|
|
|
@ -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, :name => "Canada Day", :regions => [:ca]},
|
||||
7 => [{:mday => 1, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :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]},
|
||||
|
|
|
@ -11,7 +11,7 @@ module Holidays
|
|||
#
|
||||
# More definitions are available at http://code.dunae.ca/holidays.
|
||||
module NORTH_AMERICA # :nodoc:
|
||||
DEFINED_REGIONS = [:ca, :ca_qc, :us, :ca_nf, :ca_nt, :ca_nu, :ca_ab, :ca_on, :ca_sk, :ca_mb, :ca_bc, :ca_ns, :ca_yk, :mx, :mx_pue, :us_dc]
|
||||
DEFINED_REGIONS = [:ca, :ca_qc, :ca_nf, :ca_nt, :ca_nu, :ca_ab, :ca_on, :ca_sk, :ca_mb, :ca_bc, :ca_ns, :ca_yk, :us, :mx, :mx_pue, :us_dc]
|
||||
|
||||
HOLIDAYS_BY_MONTH = {
|
||||
5 => [{:function => lambda { |year| Holidays.ca_victoria_day(year) }, :function_id => "ca_victoria_day(year)", :name => "Victoria Day", :regions => [:ca]},
|
||||
|
@ -23,34 +23,37 @@ module Holidays
|
|||
{:mday => 10, :type => :informal, :name => "Día de la Madre", :regions => [:mx]},
|
||||
{:mday => 15, :type => :informal, :name => "Día del Maestro", :regions => [:mx]},
|
||||
{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:us]}],
|
||||
0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Good Friday", :regions => [:ca, :us]},
|
||||
{:function => lambda { |year| Holidays.easter(year)+1 }, :function_id => "easter(year)+1", :type => :informal, :name => "Easter Monday", :regions => [:ca]}],
|
||||
0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Good Friday", :regions => [:ca]},
|
||||
{:function => lambda { |year| Holidays.easter(year)+1 }, :function_id => "easter(year)+1", :type => :informal, :name => "Easter Monday", :regions => [:ca]},
|
||||
{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :type => :informal, :name => "Good Friday", :regions => [:us]}],
|
||||
11 => [{:mday => 11, :name => "Rememberance Day", :regions => [:ca]},
|
||||
{: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, :name => "Veterans Day", :regions => [:us]},
|
||||
{:mday => 11, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :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]},
|
||||
{:mday => 21, :name => "National Aboriginal Day", :regions => [:ca_nt]},
|
||||
{:wday => 0, :week => 3, :type => :informal, :name => "Día del Padre", :regions => [:mx]}],
|
||||
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:ca, :us]},
|
||||
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:ca]},
|
||||
{: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]},
|
||||
{: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, :us]},
|
||||
12 => [{:mday => 25, :name => "Christmas Day", :regions => [:ca]},
|
||||
{:mday => 26, :name => "Boxing Day", :regions => [:ca]},
|
||||
{:mday => 12, :type => :informal, :name => "Día de la Virgen de Guadalupe", :regions => [:mx]},
|
||||
{:mday => 24, :type => :informal, :name => "Nochebuena", :regions => [:mx]},
|
||||
{:mday => 25, :name => "Navidad", :regions => [:mx]},
|
||||
{:mday => 28, :name => "Los Santos Inocentes", :regions => [:mx]}],
|
||||
7 => [{:mday => 1, :name => "Canada Day", :regions => [:ca]},
|
||||
{: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 => 12, :name => "Orangemen's Day", :regions => [:ca_nf]},
|
||||
{:mday => 9, :name => "Nunavut Day", :regions => [:ca_nu]},
|
||||
{:mday => 4, :name => "Independence Day", :regions => [:us]}],
|
||||
{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :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, :name => "Veterans Day", :regions => [:us]},
|
||||
11 => [{:mday => 11, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :name => "Veterans Day", :regions => [:us]},
|
||||
{:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:us]}],
|
||||
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:us]},
|
||||
1 => [{:mday => 1, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :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 => [:us]}],
|
||||
7 => [{:mday => 4, :name => "Independence Day", :regions => [:us]}],
|
||||
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]}],
|
||||
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]}],
|
||||
|
|
|
@ -52,31 +52,43 @@ class HolidaysTests < Test::Unit::TestCase
|
|||
assert_equal 1, holidays.length
|
||||
end
|
||||
|
||||
def test_any_region
|
||||
# Should return Victoria Day and Father's Day.
|
||||
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
|
||||
assert_equal 2, holidays.length
|
||||
def test_observed_dates
|
||||
# Should fall on Tuesday the 1st
|
||||
assert_equal 1, Holidays.on(Date.civil(2008,7,1), :ca, :observed).length
|
||||
|
||||
# Should return Victoria Day, Father's Day and National Patriotes Day.
|
||||
# Should fall on Monday the 2nd
|
||||
assert_equal 1, Holidays.on(Date.civil(2007,7,2), :ca, :observed).length
|
||||
end
|
||||
|
||||
def test_any_region
|
||||
# Should return Victoria Day.
|
||||
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
|
||||
assert_equal 1, holidays.length
|
||||
|
||||
# Should return Victoria Day and National Patriotes Day.
|
||||
#
|
||||
# Should be 3 in the CA region but other regional files are loaded during the
|
||||
# Should be 2 in the CA region but other regional files are loaded during the
|
||||
# unit tests add to the :any count.
|
||||
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), [:any])
|
||||
assert holidays.length >= 2
|
||||
|
||||
# Test blank region
|
||||
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31))
|
||||
assert holidays.length >= 3
|
||||
end
|
||||
|
||||
def test_sub_regions
|
||||
# Should return Victoria Day and Father's Day.
|
||||
# Should return Victoria Day.
|
||||
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
|
||||
assert_equal 2, holidays.length
|
||||
assert_equal 1, holidays.length
|
||||
|
||||
# Should return Victoria Day, Father's Day and National Patriotes Day.
|
||||
# Should return Victoria Da and National Patriotes Day.
|
||||
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca_qc)
|
||||
assert 3, holidays.length
|
||||
assert 2, holidays.length
|
||||
|
||||
# Should return Victoria Day, Father's Day and National Patriotes Day.
|
||||
# Should return Victoria Day and National Patriotes Day.
|
||||
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca_)
|
||||
assert_equal 3, holidays.length
|
||||
assert_equal 2, holidays.length
|
||||
end
|
||||
|
||||
def test_easter_sunday
|
||||
|
@ -99,7 +111,7 @@ class HolidaysTests < Test::Unit::TestCase
|
|||
|
||||
[Date.civil(1800,4,14), Date.civil(1899,4,3), Date.civil(1900,4,16),
|
||||
Date.civil(2008,3,24), Date.civil(2035,3,26)].each do |date|
|
||||
assert_equal 'Easter Monday', Holidays.on(date, :ca_qc)[0][:name]
|
||||
assert_equal 'Easter Monday', Holidays.on(date, :ca_qc, :informal)[0][:name]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2009,10,3) => 'Tag der Deutschen Einheit',
|
||||
Date.civil(2009,12,25) => '1. Weihnachtstag',
|
||||
Date.civil(2009,12,26) => '2. Weihnachtstag'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :de)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :de, :informal)[0][:name]
|
||||
end
|
||||
|
||||
[:de_bw, :de_by, :de_he, :de_nw, :de_rp, :de_sl, :de_sn, :de_th, :de_].each do |r|
|
||||
|
@ -51,7 +51,7 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2009,12,6) => 'Día de la Constitución',
|
||||
Date.civil(2009,12,8) => 'Inmaculada Concepción',
|
||||
Date.civil(2009,12,25) => 'Navidad del Señor'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :es)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :es, :informal)[0][:name]
|
||||
end
|
||||
|
||||
[:es_pv, :es_ct, :es_na, :es_v, :es_vc, :es_].each do |r|
|
||||
|
@ -103,7 +103,7 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2007,11,1) => 'Toussaint',
|
||||
Date.civil(2007,11,11) => 'Armistice 1918',
|
||||
Date.civil(2007,12,25) => 'Nöel'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :fr)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :fr, :informal)[0][:name]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,10 +120,10 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2008,11,5) => 'Guy Fawkes Day',
|
||||
Date.civil(2008,12,25) => 'Christmas Day',
|
||||
Date.civil(2008,12,26) => 'Boxing Day'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :gb)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :gb, :informal)[0][:name]
|
||||
end
|
||||
|
||||
assert_equal 'St. Patrick\'s Day', Date.civil(2008,3,17).holidays(:gb_nir)[0][:name]
|
||||
assert_equal 'St. Patrick\'s Day', Date.civil(2008,3,17).holidays(:gb_nir, :informal)[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]
|
||||
|
@ -141,7 +141,7 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2008,8,4) => 'Bank Holiday',
|
||||
Date.civil(2008,12,25) => 'Christmas Day',
|
||||
Date.civil(2008,12,26) => 'St. Stephen\'s Day'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :ie)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :ie, :informal)[0][:name]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -159,7 +159,7 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2007,12,8) => 'Immacolata Concezione',
|
||||
Date.civil(2007,12,25) => 'Natale',
|
||||
Date.civil(2007,12,26) => 'Santo Stefano'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :it)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :it, :informal)[0][:name]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -175,7 +175,7 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2008,5,12) => 'Pinksteren', # Pentecost, Easter+50
|
||||
Date.civil(2008,12,25) => 'Kerstmis',
|
||||
Date.civil(2008,12,26) => 'Kerstmis'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :nl)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :nl, :informal)[0][:name]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -199,7 +199,7 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2008,12,1) => 'Restauração da Independência',
|
||||
Date.civil(2008,12,8) => 'Imaculada Conceição',
|
||||
Date.civil(2008,12,25) => 'Natal'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :pt)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :pt, :informal)[0][:name]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -223,7 +223,7 @@ class RegionTests < Test::Unit::TestCase
|
|||
Date.civil(2008,11,1) => 'Alla helgons dag',
|
||||
Date.civil(2008,12,25) => 'Juldagen',
|
||||
Date.civil(2008,12,26) => 'Annandag jul'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :se)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :se, :informal)[0][:name]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class North_AmericaTests < Test::Unit::TestCase
|
|||
Date.civil(2008,11,11) => 'Rememberance Day',
|
||||
Date.civil(2008,12,25) => 'Christmas Day',
|
||||
Date.civil(2008,12,26) => 'Boxing Day'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :ca)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :ca, :informal)[0][:name]
|
||||
end
|
||||
|
||||
# Victoria Day
|
||||
|
@ -39,7 +39,7 @@ class North_AmericaTests < Test::Unit::TestCase
|
|||
Date.civil(2007,11,2) => 'Los Fieles Difuntos',
|
||||
Date.civil(2007,11,19) => 'Día de la Revolución',
|
||||
Date.civil(2007,12,25) => 'Navidad'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :mx)[0][:name]
|
||||
assert_equal name, Holidays.on(date, :mx, :informal)[0][:name]
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue