holidays 11.4.0 → 11.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +1 -0
- data/lib/generated_definitions/MANIFEST +1 -0
- data/lib/generated_definitions/REGIONS.rb +3 -3
- data/lib/generated_definitions/ar.rb +1 -18
- data/lib/generated_definitions/at.rb +1 -3
- data/lib/generated_definitions/au.rb +1 -86
- data/lib/generated_definitions/be_fr.rb +1 -3
- data/lib/generated_definitions/be_nl.rb +1 -3
- data/lib/generated_definitions/bg.rb +1 -3
- data/lib/generated_definitions/br.rb +1 -3
- data/lib/generated_definitions/by.rb +1 -3
- data/lib/generated_definitions/ca.rb +4 -14
- data/lib/generated_definitions/ch.rb +1 -48
- data/lib/generated_definitions/cl.rb +1 -33
- data/lib/generated_definitions/cn.rb +39 -0
- data/lib/generated_definitions/co.rb +1 -12
- data/lib/generated_definitions/cr.rb +1 -3
- data/lib/generated_definitions/cy.rb +1 -3
- data/lib/generated_definitions/cz.rb +1 -3
- data/lib/generated_definitions/de.rb +2 -14
- data/lib/generated_definitions/dk.rb +1 -3
- data/lib/generated_definitions/ecbtarget.rb +1 -3
- data/lib/generated_definitions/ee.rb +1 -3
- data/lib/generated_definitions/es.rb +1 -3
- data/lib/generated_definitions/europe.rb +4 -94
- data/lib/generated_definitions/federalreserve.rb +1 -3
- data/lib/generated_definitions/federalreservebanks.rb +1 -3
- data/lib/generated_definitions/fedex.rb +1 -7
- data/lib/generated_definitions/fi.rb +1 -25
- data/lib/generated_definitions/fr.rb +1 -3
- data/lib/generated_definitions/gb.rb +1 -3
- data/lib/generated_definitions/ge.rb +1 -3
- data/lib/generated_definitions/gr.rb +1 -3
- data/lib/generated_definitions/hk.rb +1 -3
- data/lib/generated_definitions/hr.rb +1 -3
- data/lib/generated_definitions/hu.rb +1 -3
- data/lib/generated_definitions/ie.rb +1 -12
- data/lib/generated_definitions/il.rb +1 -3
- data/lib/generated_definitions/in.rb +1 -3
- data/lib/generated_definitions/is.rb +1 -13
- data/lib/generated_definitions/it.rb +1 -3
- data/lib/generated_definitions/jp.rb +1 -95
- data/lib/generated_definitions/ke.rb +1 -3
- data/lib/generated_definitions/kr.rb +4 -6
- data/lib/generated_definitions/kz.rb +1 -3
- data/lib/generated_definitions/li.rb +1 -3
- data/lib/generated_definitions/lt.rb +1 -3
- data/lib/generated_definitions/lu.rb +1 -3
- data/lib/generated_definitions/lv.rb +1 -17
- data/lib/generated_definitions/ma.rb +1 -3
- data/lib/generated_definitions/mc.rb +1 -3
- data/lib/generated_definitions/mt_en.rb +1 -3
- data/lib/generated_definitions/mt_mt.rb +1 -3
- data/lib/generated_definitions/mx.rb +4 -4
- data/lib/generated_definitions/my.rb +1 -3
- data/lib/generated_definitions/nerc.rb +1 -3
- data/lib/generated_definitions/ng.rb +1 -3
- data/lib/generated_definitions/nl.rb +1 -3
- data/lib/generated_definitions/no.rb +1 -3
- data/lib/generated_definitions/northamerica.rb +5 -99
- data/lib/generated_definitions/nyse.rb +1 -3
- data/lib/generated_definitions/nz.rb +4 -70
- data/lib/generated_definitions/pe.rb +1 -3
- data/lib/generated_definitions/ph.rb +1 -9
- data/lib/generated_definitions/pl.rb +1 -3
- data/lib/generated_definitions/pt.rb +1 -3
- data/lib/generated_definitions/ro.rb +3 -5
- data/lib/generated_definitions/rs_cyrl.rb +1 -3
- data/lib/generated_definitions/rs_la.rb +1 -3
- data/lib/generated_definitions/ru.rb +1 -3
- data/lib/generated_definitions/scandinavia.rb +1 -47
- data/lib/generated_definitions/se.rb +1 -15
- data/lib/generated_definitions/sg.rb +1 -3
- data/lib/generated_definitions/si.rb +1 -3
- data/lib/generated_definitions/sk.rb +1 -3
- data/lib/generated_definitions/southamerica.rb +1 -57
- data/lib/generated_definitions/th.rb +1 -3
- data/lib/generated_definitions/tn.rb +1 -3
- data/lib/generated_definitions/tr.rb +1 -29
- data/lib/generated_definitions/tsx.rb +1 -13
- data/lib/generated_definitions/ua.rb +1 -3
- data/lib/generated_definitions/unitednations.rb +1 -3
- data/lib/generated_definitions/ups.rb +1 -7
- data/lib/generated_definitions/us.rb +5 -89
- data/lib/generated_definitions/ve.rb +1 -3
- data/lib/generated_definitions/vn.rb +1 -3
- data/lib/generated_definitions/za.rb +1 -3
- data/lib/holidays/{load_all_definitions.rb → bootstrap.rb} +15 -8
- data/lib/holidays/date_calculator/hijri_date.rb +52 -0
- data/lib/holidays/date_calculator/lunar_date.rb +2 -1
- data/lib/holidays/definition/context/generator.rb +4 -0
- data/lib/holidays/definition/context/merger.rb +6 -1
- data/lib/holidays/definition/custom_methods/ar.rb +28 -0
- data/lib/holidays/definition/custom_methods/au.rb +96 -0
- data/lib/holidays/definition/custom_methods/ca.rb +23 -0
- data/lib/holidays/definition/custom_methods/ch.rb +58 -0
- data/lib/holidays/definition/custom_methods/cl.rb +43 -0
- data/lib/holidays/definition/custom_methods/cn.rb +31 -0
- data/lib/holidays/definition/custom_methods/co.rb +22 -0
- data/lib/holidays/definition/custom_methods/de.rb +23 -0
- data/lib/holidays/definition/custom_methods/fedex.rb +17 -0
- data/lib/holidays/definition/custom_methods/fi.rb +35 -0
- data/lib/holidays/definition/custom_methods/ie.rb +22 -0
- data/lib/holidays/definition/custom_methods/is.rb +23 -0
- data/lib/holidays/definition/custom_methods/jp.rb +107 -0
- data/lib/holidays/definition/custom_methods/kr.rb +17 -0
- data/lib/holidays/definition/custom_methods/lv.rb +27 -0
- data/lib/holidays/definition/custom_methods/nz.rb +77 -0
- data/lib/holidays/definition/custom_methods/ph.rb +19 -0
- data/lib/holidays/definition/custom_methods/registry.rb +104 -0
- data/lib/holidays/definition/custom_methods/se.rb +25 -0
- data/lib/holidays/definition/custom_methods/tr.rb +68 -0
- data/lib/holidays/definition/custom_methods/us.rb +119 -0
- data/lib/holidays/definition/generator/module.rb +7 -4
- data/lib/holidays/definition/repository/proc_result_cache.rb +4 -0
- data/lib/holidays/factory/date_calculator.rb +6 -1
- data/lib/holidays/factory/definition.rb +2 -0
- data/lib/holidays/version.rb +1 -1
- data/lib/holidays.rb +4 -2
- metadata +25 -2
|
@@ -58,8 +58,7 @@ module Holidays
|
|
|
58
58
|
{:mday => 20, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "West Virginia Day", :regions => [:us_wv]},
|
|
59
59
|
{:wday => 0, :week => 3, :type => :informal, :name => "Father's Day", :regions => [:us, :ca]}],
|
|
60
60
|
7 => [{:mday => 3, :name => "Emancipation Day", :regions => [:us_vi]},
|
|
61
|
-
{:mday => 4, :name => "Independence Day", :regions => [:us]},
|
|
62
|
-
{:mday => 4, :function => "to_weekday_if_weekend(date)", :function_arguments => [:date], :name => "Independence Day (Holiday)", :regions => [:us_va]},
|
|
61
|
+
{:mday => 4, :observed => "independence_day(region, date)", :observed_arguments => [:region, :date], :name => "Independence Day", :regions => [:us]},
|
|
63
62
|
{:mday => 24, :name => "Pioneer Day", :regions => [:us_ut]}],
|
|
64
63
|
8 => [{:wday => 1, :week => 2, :name => "Victory Day", :regions => [:us_ri]},
|
|
65
64
|
{:mday => 16, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Bennington Battle Day", :regions => [:us_vt]},
|
|
@@ -82,7 +81,9 @@ module Holidays
|
|
|
82
81
|
{:function => "day_after_thanksgiving(year)", :function_arguments => [:year], :name => "Presidents' Day", :regions => [:us_nm]},
|
|
83
82
|
{:function => "day_after_thanksgiving(year)", :function_arguments => [:year], :name => "Lincoln's Birthday", :regions => [:us_in]},
|
|
84
83
|
{:function => "day_after_thanksgiving(year)", :function_arguments => [:year], :name => "American Indian Heritage Day", :regions => [:us_md]},
|
|
85
|
-
{:function => "day_after_thanksgiving(year)", :function_arguments => [:year], :name => "Day after Thanksgiving (Black Friday)", :regions => [:us_ca, :us_de, :us_fl, :us_ia, :us_il, :us_ks, :us_ky, :us_me, :us_mi, :us_mn, :us_ms, :us_ne, :us_nh, :us_nc, :us_pa, :us_sc, :us_ok, :us_tn, :us_tx, :us_va, :us_wa, :us_wv]}
|
|
84
|
+
{:function => "day_after_thanksgiving(year)", :function_arguments => [:year], :name => "Day after Thanksgiving (Black Friday)", :regions => [:us_ca, :us_de, :us_fl, :us_ia, :us_il, :us_ks, :us_ky, :us_me, :us_mi, :us_mn, :us_ms, :us_ne, :us_nh, :us_nc, :us_pa, :us_sc, :us_ok, :us_tn, :us_tx, :us_va, :us_wa, :us_wv]},
|
|
85
|
+
{:mday => 1, :type => :informal, :name => "Day of the Dead", :regions => [:us, :ca]},
|
|
86
|
+
{:mday => 2, :type => :informal, :name => "Day of the Dead", :regions => [:us, :ca]}],
|
|
86
87
|
12 => [{:mday => 24, :name => "Christmas Eve", :regions => [:us_ar, :us_mi, :us_nc, :us_sc, :us_tx, :us_wi]},
|
|
87
88
|
{:mday => 24, :function => "christmas_eve_holiday(date)", :function_arguments => [:date], :name => "Christmas Eve (Holiday)", :regions => [:us_mi, :us_sc, :us_va]},
|
|
88
89
|
{:mday => 25, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Christmas Day", :regions => [:us]},
|
|
@@ -92,92 +93,7 @@ module Holidays
|
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
def self.custom_methods
|
|
95
|
-
{
|
|
96
|
-
"christmas_eve_holiday(date)" => Proc.new { |date|
|
|
97
|
-
beginning_of_month = Date.civil(date.year, date.month, 1)
|
|
98
|
-
(date.saturday? || date.sunday?) ? date.downto(beginning_of_month).find {|d| d if d.wday == 5} : date
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
"rosh_hashanah(year)" => Proc.new { |year|
|
|
102
|
-
rosh_hashanah_dates = {
|
|
103
|
-
'2014' => Date.civil(2014, 9, 25),
|
|
104
|
-
'2015' => Date.civil(2015, 9, 14),
|
|
105
|
-
'2016' => Date.civil(2016, 10, 3),
|
|
106
|
-
'2017' => Date.civil(2017, 9, 21),
|
|
107
|
-
'2018' => Date.civil(2018, 9, 10),
|
|
108
|
-
'2019' => Date.civil(2019, 9, 30),
|
|
109
|
-
'2020' => Date.civil(2020, 9, 19)
|
|
110
|
-
}
|
|
111
|
-
rosh_hashanah_dates[year.to_s]
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
"yom_kippur(year)" => Proc.new { |year|
|
|
115
|
-
yom_kippur_dates = {
|
|
116
|
-
'2014' => Date.civil(2014, 10, 4),
|
|
117
|
-
'2015' => Date.civil(2015, 9, 23),
|
|
118
|
-
'2016' => Date.civil(2016, 10, 12),
|
|
119
|
-
'2017' => Date.civil(2017, 9, 30),
|
|
120
|
-
'2018' => Date.civil(2018, 9, 19),
|
|
121
|
-
'2019' => Date.civil(2019, 10, 9),
|
|
122
|
-
'2020' => Date.civil(2020, 9, 28)
|
|
123
|
-
}
|
|
124
|
-
yom_kippur_dates[year.to_s]
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
"georgia_state_holiday(year, month)" => Proc.new { |year, month|
|
|
128
|
-
beginning_of_month = Date.civil(year, month, 1)
|
|
129
|
-
state_holiday = Date.civil(year, month, 26)
|
|
130
|
-
state_holiday.downto(beginning_of_month).find {|date| date if date.wday == 1 }
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
"lee_jackson_day(year, month)" => Proc.new { |year, month|
|
|
134
|
-
day_of_holiday = Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, month, 3, 1)
|
|
135
|
-
beginning_of_month = Date.civil(year, month, 1)
|
|
136
|
-
king_day = Date.civil(year, month, day_of_holiday)
|
|
137
|
-
king_day.downto(beginning_of_month).find {|date| date if date.wday == 5 }
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
"juneteenth_national_independence_day(region, date)" => Proc.new { |region, date|
|
|
141
|
-
if region == :us_ut
|
|
142
|
-
case date.wday
|
|
143
|
-
when 1
|
|
144
|
-
date
|
|
145
|
-
when 2,3,4,5
|
|
146
|
-
date - (date.wday - 1)
|
|
147
|
-
when 6
|
|
148
|
-
date + 2
|
|
149
|
-
when 0
|
|
150
|
-
date + 1
|
|
151
|
-
end
|
|
152
|
-
elsif date.wday == 0
|
|
153
|
-
date + 1
|
|
154
|
-
elsif date.wday == 6
|
|
155
|
-
date - 1
|
|
156
|
-
else
|
|
157
|
-
date
|
|
158
|
-
end
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
"election_day(year)" => Proc.new { |year|
|
|
162
|
-
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 11, 1, 1) + 1
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
"even_year_election_day(year)" => Proc.new { |year|
|
|
166
|
-
if year % 2 == 0
|
|
167
|
-
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 11, 1, 1) + 1
|
|
168
|
-
end
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
"us_inauguration_day(year)" => Proc.new { |year|
|
|
172
|
-
year % 4 == 1 ? 20 : nil
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
"day_after_thanksgiving(year)" => Proc.new { |year|
|
|
176
|
-
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 11, 4, 4) + 1
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
96
|
+
{}
|
|
181
97
|
end
|
|
182
98
|
end
|
|
183
99
|
end
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
require 'holidays/definition/custom_methods/registry'
|
|
2
|
+
|
|
1
3
|
module Holidays
|
|
2
|
-
#
|
|
3
|
-
|
|
4
|
+
# Runs once at require time (see the bottom of lib/holidays.rb). Despite the
|
|
5
|
+
# historical name of its alias, this does NOT load per-region holiday data;
|
|
6
|
+
# that happens lazily in Definition::Context::Load. What it does:
|
|
7
|
+
# 1. Register the built-in calculation procs (easter, weekend modifiers,
|
|
8
|
+
# lunar_to_solar, calculate_day_of_month) into custom_methods_repository.
|
|
9
|
+
# 2. Register the native per-region custom methods (CustomMethods.all).
|
|
10
|
+
# 3. Require generated_definitions/REGIONS.rb (the region-name list only).
|
|
11
|
+
class Bootstrap
|
|
4
12
|
class << self
|
|
5
13
|
def call
|
|
6
|
-
#FIXME I need a better way to do this. I'm thinking of putting these 'common' methods
|
|
7
|
-
# into some kind of definition file so it can be loaded automatically but I'm afraid
|
|
8
|
-
# of making that big of a breaking API change since these are public. For the time
|
|
9
|
-
# being I'll load them manually like this.
|
|
10
|
-
#
|
|
11
|
-
# NOTE: These are no longer public! We can do whatever we want here!
|
|
12
14
|
global_methods = {
|
|
13
15
|
"easter(year)" => gregorian_easter.method(:calculate_easter_for).to_proc,
|
|
14
16
|
"orthodox_easter(year)" => gregorian_easter.method(:calculate_orthodox_easter_for).to_proc,
|
|
@@ -29,6 +31,9 @@ module Holidays
|
|
|
29
31
|
|
|
30
32
|
Factory::Definition.custom_methods_repository.add(global_methods)
|
|
31
33
|
|
|
34
|
+
# Native per-region custom methods (replaces the old YAML methods:/ruby: blocks).
|
|
35
|
+
Factory::Definition.custom_methods_repository.add(Holidays::Definition::CustomMethods.all)
|
|
36
|
+
|
|
32
37
|
static_regions_definition = "#{Holidays::DEFINITIONS_PATH}/REGIONS.rb"
|
|
33
38
|
require static_regions_definition
|
|
34
39
|
end
|
|
@@ -56,4 +61,6 @@ module Holidays
|
|
|
56
61
|
end
|
|
57
62
|
end
|
|
58
63
|
end
|
|
64
|
+
|
|
65
|
+
private_constant :Bootstrap
|
|
59
66
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module DateCalculator
|
|
5
|
+
# Arithmetic ("tabular", a.k.a. Kuwaiti) Islamic calendar.
|
|
6
|
+
#
|
|
7
|
+
# Months alternate 30 and 29 days; leap years add a day to the twelfth
|
|
8
|
+
# month on a fixed 11-of-30 cycle. This is a purely arithmetic calendar,
|
|
9
|
+
# so it can land a day (occasionally two) either side of a locally
|
|
10
|
+
# proclaimed date. Callers that need the proclaimed date layer their own
|
|
11
|
+
# override table on top of this (see
|
|
12
|
+
# Holidays::Definition::CustomMethods::TR).
|
|
13
|
+
class HijriDate
|
|
14
|
+
# Julian day number of 1 Muharram 1 AH minus one day, chosen so that
|
|
15
|
+
# to_jd's month/day terms are added directly. Corresponds to the civil
|
|
16
|
+
# epoch (Friday, 16 July 622 CE proleptic Julian).
|
|
17
|
+
EPOCH_JDN = 1948439
|
|
18
|
+
|
|
19
|
+
def to_gregorian(hijri_year, hijri_month, hijri_day)
|
|
20
|
+
Date.jd(to_jd(hijri_year, hijri_month, hijri_day))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Given a Gregorian year and a fixed Hijri month/day, return the
|
|
24
|
+
# occurrence that falls within that Gregorian year, or nil if none does.
|
|
25
|
+
#
|
|
26
|
+
# A fixed Hijri date drifts ~11 days earlier each Gregorian year, so
|
|
27
|
+
# roughly once every 33 years it falls twice in the same Gregorian year
|
|
28
|
+
# (once in early January, once in late December). Only the earlier
|
|
29
|
+
# occurrence is returned.
|
|
30
|
+
def gregorian_year_occurrence(gregorian_year, hijri_month, hijri_day)
|
|
31
|
+
candidate_hijri_year = gregorian_year - 579
|
|
32
|
+
|
|
33
|
+
(candidate_hijri_year - 1..candidate_hijri_year + 1).each do |hijri_year|
|
|
34
|
+
date = to_gregorian(hijri_year, hijri_month, hijri_day)
|
|
35
|
+
return date if date.year == gregorian_year
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
nil
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def to_jd(year, month, day)
|
|
44
|
+
day +
|
|
45
|
+
(29.5 * (month - 1)).ceil +
|
|
46
|
+
(year - 1) * 354 +
|
|
47
|
+
(3 + 11 * year) / 30 +
|
|
48
|
+
EPOCH_JDN
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -152,7 +152,7 @@ module Holidays
|
|
|
152
152
|
[384, 1, 2, 1, 2, 1, 2, 1, 2, 4, 2, 1, 2].freeze,
|
|
153
153
|
[354, 1, 2, 1, 1, 2, 1, 2, 2, 2, 1, 2, 1].freeze,
|
|
154
154
|
[355, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2].freeze,
|
|
155
|
-
[
|
|
155
|
+
[384, 1, 2, 1, 2, 1, 5, 1, 2, 1, 2, 2, 2].freeze, # 2017 has a leap 6th month; previous entry omitted it, shifting every later date
|
|
156
156
|
[354, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2].freeze,
|
|
157
157
|
[354, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2].freeze,
|
|
158
158
|
[384, 2, 1, 2, 4, 2, 1, 1, 2, 1, 2, 1, 2].freeze,
|
|
@@ -503,6 +503,7 @@ module Holidays
|
|
|
503
503
|
vn: VIETNAMESE_LUNAR_YEAR_INFO,
|
|
504
504
|
hk: CHINESE_LUNAR_YEAR_INFO,
|
|
505
505
|
sg: CHINESE_LUNAR_YEAR_INFO,
|
|
506
|
+
cn: CHINESE_LUNAR_YEAR_INFO,
|
|
506
507
|
}.freeze
|
|
507
508
|
|
|
508
509
|
# Provides number of days per lunar month type. Lunar months
|
|
@@ -132,6 +132,10 @@ module Holidays
|
|
|
132
132
|
rule[:function_arguments] = get_function_arguments(rule[:function], parsed_custom_methods)
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
+
if rule[:observed]
|
|
136
|
+
rule[:observed_arguments] = get_function_arguments(rule[:observed], parsed_custom_methods)
|
|
137
|
+
end
|
|
138
|
+
|
|
135
139
|
rules_by_month[month] << rule
|
|
136
140
|
end
|
|
137
141
|
end
|
|
@@ -3,10 +3,12 @@ module Holidays
|
|
|
3
3
|
module Context
|
|
4
4
|
# Merge a new set of definitions into the Holidays module.
|
|
5
5
|
class Merger
|
|
6
|
-
def initialize(holidays_by_month_repo, regions_repo, custom_methods_repo)
|
|
6
|
+
def initialize(holidays_by_month_repo, regions_repo, custom_methods_repo, cache_repo, proc_result_cache_repo)
|
|
7
7
|
@holidays_repo = holidays_by_month_repo
|
|
8
8
|
@regions_repo = regions_repo
|
|
9
9
|
@custom_methods_repo = custom_methods_repo
|
|
10
|
+
@cache_repo = cache_repo
|
|
11
|
+
@proc_result_cache_repo = proc_result_cache_repo
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def call(target_regions, target_holidays, target_custom_methods, target_custom_method_sources = {})
|
|
@@ -17,6 +19,9 @@ module Holidays
|
|
|
17
19
|
target_custom_method_sources,
|
|
18
20
|
derive_function_regions(target_holidays),
|
|
19
21
|
)
|
|
22
|
+
ensure
|
|
23
|
+
@cache_repo.reset!
|
|
24
|
+
@proc_result_cache_repo.reset!
|
|
20
25
|
end
|
|
21
26
|
|
|
22
27
|
private
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# ar custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/ar.yaml.
|
|
8
|
+
module AR
|
|
9
|
+
class << self
|
|
10
|
+
def to_nearest_monday(date)
|
|
11
|
+
case date.wday
|
|
12
|
+
when 5
|
|
13
|
+
date += 3
|
|
14
|
+
when 4
|
|
15
|
+
date += 4
|
|
16
|
+
when 3
|
|
17
|
+
date -= 2
|
|
18
|
+
when 2
|
|
19
|
+
date -= 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
date
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# au custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/au.yaml.
|
|
8
|
+
module AU
|
|
9
|
+
class << self
|
|
10
|
+
def afl_grand_final(year)
|
|
11
|
+
case year
|
|
12
|
+
when 2015
|
|
13
|
+
Date.civil(2015, 10, 2)
|
|
14
|
+
when 2016
|
|
15
|
+
Date.civil(2016, 9, 30)
|
|
16
|
+
when 2017
|
|
17
|
+
Date.civil(2017, 9, 29)
|
|
18
|
+
when 2020
|
|
19
|
+
Date.civil(2020, 10, 23)
|
|
20
|
+
when 2022
|
|
21
|
+
Date.civil(2022, 9, 23)
|
|
22
|
+
else
|
|
23
|
+
# Friday before AFL Grand Final typically falls on the last Friday in September
|
|
24
|
+
# Override when falls on a different date
|
|
25
|
+
last_day = Date.civil(year, 9, -1)
|
|
26
|
+
last_friday = last_day - ((last_day.wday - 5) % 7)
|
|
27
|
+
last_friday
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def qld_queens_bday_october(year)
|
|
32
|
+
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 1, 1)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def qld_kings_bday_october(year)
|
|
36
|
+
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 1, 1)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def qld_queens_birthday_june(year)
|
|
40
|
+
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 6, 2, 1)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def qld_labour_day_may(year)
|
|
44
|
+
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 5, 1, 1)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def qld_labour_day_october(year)
|
|
48
|
+
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 1, 1)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def hobart_show_day(year)
|
|
52
|
+
fourth_sat_in_oct = Date.civil(year, 10, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 4, :saturday))
|
|
53
|
+
fourth_sat_in_oct - 2 # the thursday before
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def march_pub_hol_sa(year)
|
|
57
|
+
Date.civil(year, 3, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 3, :second, :monday))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def may_pub_hol_sa(year)
|
|
61
|
+
Date.civil(year, 5, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 5, :third, :monday))
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def qld_brisbane_ekka_holiday(year)
|
|
65
|
+
first_friday = Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 8, :first, :friday)
|
|
66
|
+
|
|
67
|
+
if first_friday < 5
|
|
68
|
+
second_friday = Date.civil(year, 8, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 8, :second, :friday))
|
|
69
|
+
second_friday + 5 # The next Wednesday
|
|
70
|
+
else
|
|
71
|
+
Date.civil(year, 8, first_friday) + 5
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def to_nearest_monday_after(date)
|
|
76
|
+
case date.wday
|
|
77
|
+
when 6
|
|
78
|
+
date += 2
|
|
79
|
+
when 5
|
|
80
|
+
date += 3
|
|
81
|
+
when 4
|
|
82
|
+
date += 4
|
|
83
|
+
when 3
|
|
84
|
+
date += 5
|
|
85
|
+
when 2
|
|
86
|
+
date += 6
|
|
87
|
+
when 0
|
|
88
|
+
date += 1
|
|
89
|
+
end
|
|
90
|
+
date
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# ca custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/ca.yaml.
|
|
8
|
+
module CA
|
|
9
|
+
class << self
|
|
10
|
+
def ca_victoria_day(year)
|
|
11
|
+
date = Date.civil(year,5,24)
|
|
12
|
+
if date.wday > 1
|
|
13
|
+
date -= (date.wday - 1)
|
|
14
|
+
elsif date.wday == 0
|
|
15
|
+
date -= 6
|
|
16
|
+
end
|
|
17
|
+
date
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# ch custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/ch.yaml.
|
|
8
|
+
module CH
|
|
9
|
+
class << self
|
|
10
|
+
def ch_vd_lundi_du_jeune_federal(year)
|
|
11
|
+
date = Date.civil(year,9,1)
|
|
12
|
+
# Find the first Sunday of September
|
|
13
|
+
until date.wday.eql? 0 do
|
|
14
|
+
date += 1
|
|
15
|
+
end
|
|
16
|
+
# There are 15 days between the first Sunday
|
|
17
|
+
# and the Monday after the third Sunday
|
|
18
|
+
date + 15
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def ch_ge_jeune_genevois(year)
|
|
22
|
+
date = Date.civil(year,9,1)
|
|
23
|
+
# Find the first Sunday of September
|
|
24
|
+
until date.wday.eql? 0 do
|
|
25
|
+
date += 1
|
|
26
|
+
end
|
|
27
|
+
# Thursday is four days after Sunday
|
|
28
|
+
date + 4
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def ch_gl_naefelser_fahrt(year)
|
|
32
|
+
date = Date.civil(year,4,1)
|
|
33
|
+
# Find the first Thursday of April
|
|
34
|
+
until date.wday.eql? 4 do
|
|
35
|
+
date += 1
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if date.eql?(Holidays::Factory::DateCalculator::Easter::Gregorian.easter_calculator.calculate_easter_for(year)-3)
|
|
39
|
+
date += 7
|
|
40
|
+
end
|
|
41
|
+
date
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def ch_be_zibelemaerit(year)
|
|
45
|
+
date = Date.civil(year,11,1)
|
|
46
|
+
# Find the first Monday of November
|
|
47
|
+
until date.wday.eql? 1 do
|
|
48
|
+
date += 1
|
|
49
|
+
end
|
|
50
|
+
# There are 21 days between the first monday
|
|
51
|
+
# and the 4rth Monday after
|
|
52
|
+
date + 21
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# cl custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/cl.yaml.
|
|
8
|
+
module CL
|
|
9
|
+
class << self
|
|
10
|
+
def st_peter_st_paul_cl(year)
|
|
11
|
+
date = Date.civil(year, 6, 29)
|
|
12
|
+
if [2,3,4].include?(date.wday)
|
|
13
|
+
date -= (date.wday - 1)
|
|
14
|
+
elsif date.wday == 5
|
|
15
|
+
date += 3
|
|
16
|
+
end
|
|
17
|
+
date
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def columbus_day_cl(year)
|
|
21
|
+
date = Date.civil(year, 10, 12)
|
|
22
|
+
if [2,3,4].include?(date.wday)
|
|
23
|
+
date -= (date.wday - 1)
|
|
24
|
+
elsif date.wday == 5
|
|
25
|
+
date += 3
|
|
26
|
+
end
|
|
27
|
+
date
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def other_churches_day_cl(year)
|
|
31
|
+
date = Date.civil(year, 10, 31)
|
|
32
|
+
if date.wday == 2
|
|
33
|
+
date -= 4
|
|
34
|
+
elsif date.wday == 3
|
|
35
|
+
date += 2
|
|
36
|
+
end
|
|
37
|
+
date
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# cn custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/cn.yaml.
|
|
8
|
+
module CN
|
|
9
|
+
class << self
|
|
10
|
+
# Qingming falls when the sun reaches celestial longitude 15 degrees,
|
|
11
|
+
# which lands on 4 or 5 April. This is the standard solar-term
|
|
12
|
+
# approximation; the century constant shifts between the 20th and
|
|
13
|
+
# 21st centuries.
|
|
14
|
+
def cn_qingming(year)
|
|
15
|
+
constant =
|
|
16
|
+
case year
|
|
17
|
+
when 1900..1999
|
|
18
|
+
5.59
|
|
19
|
+
when 2000..2099
|
|
20
|
+
4.81
|
|
21
|
+
else
|
|
22
|
+
raise IndexError.new("Out of range")
|
|
23
|
+
end
|
|
24
|
+
y = year % 100
|
|
25
|
+
Date.civil(year, 4, (y * 0.2422 + constant).floor - (y / 4))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# co custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/co.yaml.
|
|
8
|
+
module CO
|
|
9
|
+
class << self
|
|
10
|
+
def to_following_monday_if_not_monday(date)
|
|
11
|
+
if date.wday > 1
|
|
12
|
+
date += ( 8 - date.wday )
|
|
13
|
+
elsif date.wday == 0
|
|
14
|
+
date += 1
|
|
15
|
+
end
|
|
16
|
+
date
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# de custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/de.yaml.
|
|
8
|
+
module DE
|
|
9
|
+
class << self
|
|
10
|
+
def de_buss_und_bettag(year)
|
|
11
|
+
date = Date.civil(year,11,23)
|
|
12
|
+
if date.wday > 3
|
|
13
|
+
date -= (date.wday - 3)
|
|
14
|
+
else
|
|
15
|
+
date -= (date.wday + 4)
|
|
16
|
+
end
|
|
17
|
+
date
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# fedex custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/fedex.yaml.
|
|
8
|
+
module FEDEX
|
|
9
|
+
class << self
|
|
10
|
+
def day_after_thanksgiving(year)
|
|
11
|
+
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 11, 4, 4) + 1
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module Holidays
|
|
4
|
+
module Definition
|
|
5
|
+
module CustomMethods
|
|
6
|
+
# fi custom holiday calculations, ported verbatim from the
|
|
7
|
+
# +methods:+ block in definitions/fi.yaml.
|
|
8
|
+
module FI
|
|
9
|
+
class << self
|
|
10
|
+
def fi_juhannusaatto(year)
|
|
11
|
+
date = Date.civil(year,6,19)
|
|
12
|
+
if date.wday > 5 #if 19.6 is saturday
|
|
13
|
+
date += 6
|
|
14
|
+
else
|
|
15
|
+
date += (5 - date.wday)
|
|
16
|
+
end
|
|
17
|
+
date
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def fi_juhannuspaiva(year)
|
|
21
|
+
date = Date.civil(year,6,20)
|
|
22
|
+
date += (6 - date.wday)
|
|
23
|
+
date
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def fi_pyhainpaiva(year)
|
|
27
|
+
date = Date.civil(year,10,31)
|
|
28
|
+
date += (6 - date.wday)
|
|
29
|
+
date
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|