holidays 3.3.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -0
  3. data/CONTRIBUTING.md +37 -0
  4. data/README.md +16 -25
  5. data/REFERENCES +4 -1
  6. data/Rakefile +38 -8
  7. data/benchmark.rb +8 -0
  8. data/definitions/README.md +187 -8
  9. data/definitions/ar.yaml +2 -1
  10. data/definitions/at.yaml +17 -13
  11. data/definitions/au.yaml +65 -60
  12. data/definitions/be_fr.yaml +14 -10
  13. data/definitions/be_nl.yaml +8 -4
  14. data/definitions/bg.yaml +12 -6
  15. data/definitions/br.yaml +6 -3
  16. data/definitions/ca.yaml +8 -6
  17. data/definitions/ch.yaml +21 -15
  18. data/definitions/cl.yaml +4 -2
  19. data/definitions/cr.yaml +5 -3
  20. data/definitions/cz.yaml +4 -2
  21. data/definitions/de.yaml +25 -14
  22. data/definitions/dk.yaml +26 -17
  23. data/definitions/ecb_target.yaml +4 -2
  24. data/definitions/el.yaml +23 -18
  25. data/definitions/es.yaml +31 -28
  26. data/definitions/federal_reserve.yaml +12 -12
  27. data/definitions/fedex.yaml +6 -6
  28. data/definitions/fi.yaml +26 -25
  29. data/definitions/fr.yaml +8 -4
  30. data/definitions/gb.yaml +9 -7
  31. data/definitions/hr.yaml +8 -6
  32. data/definitions/hu.yaml +8 -6
  33. data/definitions/ie.yaml +17 -16
  34. data/definitions/index.yaml +1 -1
  35. data/definitions/is.yaml +29 -19
  36. data/definitions/it.yaml +10 -9
  37. data/definitions/jp.yaml +92 -44
  38. data/definitions/li.yaml +25 -20
  39. data/definitions/lt.yaml +2 -1
  40. data/definitions/ma.yaml +7 -7
  41. data/definitions/mx.yaml +11 -11
  42. data/definitions/nerc.yaml +6 -6
  43. data/definitions/nl.yaml +22 -18
  44. data/definitions/no.yaml +19 -11
  45. data/definitions/north_america_informal.yaml +6 -6
  46. data/definitions/nyse.yaml +9 -8
  47. data/definitions/nz.yaml +33 -29
  48. data/definitions/ph.yaml +15 -8
  49. data/definitions/pl.yaml +27 -17
  50. data/definitions/pt.yaml +4 -2
  51. data/definitions/ro.yaml +21 -18
  52. data/definitions/se.yaml +24 -18
  53. data/definitions/sg.yaml +10 -9
  54. data/definitions/si.yaml +4 -2
  55. data/definitions/sk.yaml +4 -2
  56. data/definitions/united_nations.yaml +12 -12
  57. data/definitions/ups.yaml +6 -6
  58. data/definitions/us.yaml +12 -11
  59. data/definitions/ve.yaml +8 -4
  60. data/definitions/vi.yaml +6 -6
  61. data/definitions/za.yaml +26 -24
  62. data/holidays.gemspec +3 -1
  63. data/lib/generated_definitions/MANIFEST +1 -1
  64. data/lib/generated_definitions/ar.rb +8 -6
  65. data/lib/generated_definitions/at.rb +11 -9
  66. data/lib/generated_definitions/au.rb +75 -99
  67. data/lib/generated_definitions/be.rb +12 -10
  68. data/lib/generated_definitions/be_fr.rb +12 -10
  69. data/lib/generated_definitions/be_nl.rb +12 -10
  70. data/lib/generated_definitions/bg.rb +14 -13
  71. data/lib/generated_definitions/br.rb +11 -9
  72. data/lib/generated_definitions/ca.rb +20 -20
  73. data/lib/generated_definitions/ch.rb +41 -44
  74. data/lib/generated_definitions/cl.rb +9 -7
  75. data/lib/generated_definitions/cr.rb +9 -7
  76. data/lib/generated_definitions/cz.rb +9 -6
  77. data/lib/generated_definitions/de.rb +25 -25
  78. data/lib/generated_definitions/dk.rb +17 -15
  79. data/lib/generated_definitions/ecb_target.rb +9 -7
  80. data/lib/generated_definitions/el.rb +13 -11
  81. data/lib/generated_definitions/es.rb +35 -33
  82. data/lib/generated_definitions/europe.rb +234 -247
  83. data/lib/generated_definitions/federal_reserve.rb +11 -9
  84. data/lib/generated_definitions/fedex.rb +42 -0
  85. data/lib/generated_definitions/fi.rb +32 -36
  86. data/lib/generated_definitions/fr.rb +12 -10
  87. data/lib/generated_definitions/gb.rb +15 -13
  88. data/lib/generated_definitions/hr.rb +10 -8
  89. data/lib/generated_definitions/hu.rb +9 -7
  90. data/lib/generated_definitions/ie.rb +17 -17
  91. data/lib/generated_definitions/is.rb +26 -26
  92. data/lib/generated_definitions/it.rb +9 -7
  93. data/lib/generated_definitions/jp.rb +112 -89
  94. data/lib/generated_definitions/li.rb +14 -12
  95. data/lib/generated_definitions/lt.rb +9 -7
  96. data/lib/generated_definitions/ma.rb +7 -5
  97. data/lib/generated_definitions/mx.rb +7 -5
  98. data/lib/generated_definitions/nerc.rb +10 -8
  99. data/lib/generated_definitions/nl.rb +15 -13
  100. data/lib/generated_definitions/no.rb +16 -14
  101. data/lib/generated_definitions/north_america.rb +34 -37
  102. data/lib/generated_definitions/nyse.rb +10 -8
  103. data/lib/generated_definitions/nz.rb +40 -40
  104. data/lib/generated_definitions/ph.rb +17 -13
  105. data/lib/generated_definitions/pl.rb +25 -27
  106. data/lib/generated_definitions/pt.rb +10 -8
  107. data/lib/generated_definitions/ro.rb +11 -9
  108. data/lib/generated_definitions/scandinavia.rb +92 -102
  109. data/lib/generated_definitions/se.rb +25 -27
  110. data/lib/generated_definitions/sg.rb +11 -9
  111. data/lib/generated_definitions/si.rb +10 -8
  112. data/lib/generated_definitions/sk.rb +9 -7
  113. data/lib/generated_definitions/united_nations.rb +7 -5
  114. data/lib/generated_definitions/ups.rb +13 -12
  115. data/lib/generated_definitions/us.rb +20 -21
  116. data/lib/generated_definitions/ve.rb +11 -9
  117. data/lib/generated_definitions/vi.rb +7 -5
  118. data/lib/generated_definitions/za.rb +19 -17
  119. data/lib/holidays.rb +20 -83
  120. data/lib/holidays/date_calculator/weekend_modifier.rb +22 -5
  121. data/lib/holidays/definition/context/generator.rb +67 -29
  122. data/lib/holidays/definition/context/merger.rb +8 -8
  123. data/lib/holidays/definition/decorator/custom_method_proc.rb +28 -0
  124. data/lib/holidays/definition/decorator/custom_method_source.rb +30 -0
  125. data/lib/holidays/definition/entity/custom_method.rb +11 -0
  126. data/lib/holidays/definition/parser/custom_method.rb +69 -0
  127. data/lib/holidays/definition/repository/custom_methods.rb +27 -0
  128. data/lib/holidays/definition/repository/holidays_by_month.rb +1 -1
  129. data/lib/holidays/definition/repository/{proc_cache.rb → proc_result_cache.rb} +19 -4
  130. data/lib/holidays/definition/validator/custom_method.rb +31 -0
  131. data/lib/holidays/definition_factory.rb +42 -6
  132. data/lib/holidays/errors.rb +6 -0
  133. data/lib/holidays/load_all_definitions.rb +57 -0
  134. data/lib/holidays/option/context/parse_options.rb +26 -16
  135. data/lib/holidays/option_factory.rb +1 -0
  136. data/lib/holidays/use_case/context/between.rb +41 -14
  137. data/lib/holidays/use_case_factory.rb +2 -1
  138. data/lib/holidays/version.rb +1 -1
  139. data/test/data/test_single_custom_holiday_with_custom_procs.yaml +24 -0
  140. data/test/defs/test_defs_at.rb +1 -1
  141. data/test/defs/test_defs_au.rb +3 -2
  142. data/test/defs/test_defs_cr.rb +1 -0
  143. data/test/defs/test_defs_cz.rb +1 -0
  144. data/test/defs/test_defs_dk.rb +2 -2
  145. data/test/defs/test_defs_el.rb +7 -6
  146. data/test/defs/test_defs_europe.rb +40 -33
  147. data/test/defs/test_defs_fedex.rb +24 -0
  148. data/test/defs/test_defs_fi.rb +4 -3
  149. data/test/defs/test_defs_hr.rb +2 -2
  150. data/test/defs/test_defs_hu.rb +2 -2
  151. data/test/defs/test_defs_is.rb +2 -1
  152. data/test/defs/test_defs_it.rb +2 -1
  153. data/test/defs/test_defs_jp.rb +1 -1
  154. data/test/defs/test_defs_li.rb +1 -1
  155. data/test/defs/test_defs_ma.rb +2 -1
  156. data/test/defs/test_defs_mx.rb +4 -3
  157. data/test/defs/test_defs_nl.rb +7 -6
  158. data/test/defs/test_defs_no.rb +1 -0
  159. data/test/defs/test_defs_north_america.rb +4 -3
  160. data/test/defs/test_defs_nyse.rb +2 -1
  161. data/test/defs/test_defs_pl.rb +1 -0
  162. data/test/defs/test_defs_ro.rb +11 -11
  163. data/test/defs/test_defs_scandinavia.rb +12 -8
  164. data/test/defs/test_defs_se.rb +3 -2
  165. data/test/defs/test_defs_sg.rb +2 -1
  166. data/test/defs/test_defs_vi.rb +1 -1
  167. data/test/defs/test_defs_za.rb +3 -2
  168. data/test/holidays/date_calculator/test_weekend_modifier.rb +11 -0
  169. data/test/holidays/definition/context/test_generator.rb +64 -5
  170. data/test/holidays/definition/context/test_merger.rb +5 -2
  171. data/test/holidays/definition/decorator/test_custom_method_proc.rb +113 -0
  172. data/test/holidays/definition/decorator/test_custom_method_source.rb +96 -0
  173. data/test/holidays/definition/parser/test_custom_method.rb +79 -0
  174. data/test/holidays/definition/repository/test_custom_methods.rb +43 -0
  175. data/test/holidays/definition/repository/test_holidays_by_month.rb +0 -32
  176. data/test/holidays/definition/repository/test_proc_result_cache.rb +84 -0
  177. data/test/holidays/definition/validator/test_custom_method.rb +89 -0
  178. data/test/holidays/option/context/test_parse_options.rb +5 -0
  179. data/test/holidays/test_definition_factory.rb +17 -2
  180. data/test/holidays/use_case/context/test_between.rb +2 -0
  181. data/test/test_all_regions.rb +7 -49
  182. data/test/test_custom_holidays.rb +8 -2
  183. data/test/test_helper.rb +9 -2
  184. data/test/test_holidays.rb +9 -29
  185. metadata +46 -11
  186. data/lib/generated_definitions/fed_ex.rb +0 -41
  187. data/test/holidays/definition/repository/test_proc_cache.rb +0 -29
  188. data/test/test_parse_definitions.rb +0 -30
@@ -10,7 +10,7 @@ module Holidays
10
10
  # require 'holidays'
11
11
  # require 'generated_definitions/sk'
12
12
  #
13
- # All the definitions are available at https://github.com/alexdunae/holidays
13
+ # All the definitions are available at https://github.com/holidays/holidays
14
14
  module SK # :nodoc:
15
15
  def self.defined_regions
16
16
  [:sk]
@@ -18,8 +18,8 @@ module Holidays
18
18
 
19
19
  def self.holidays_by_month
20
20
  {
21
- 0 => [{:function => lambda { |year| Holidays.easter(year)+1 }, :function_id => "easter(year)+1", :name => "Veľkonočný pondelok", :regions => [:sk]},
22
- {:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Veľký piatok", :regions => [:sk]}],
21
+ 0 => [{:function => "easter(year)", :function_arguments => [:year], :function_modifier => 1, :name => "Veľkonočný pondelok", :regions => [:sk]},
22
+ {:function => "easter(year)", :function_arguments => [:year], :function_modifier => -2, :name => "Veľký piatok", :regions => [:sk]}],
23
23
  1 => [{:mday => 1, :name => "Nový rok", :regions => [:sk]},
24
24
  {:mday => 6, :name => "Zjavenie Pána (Traja králi)", :regions => [:sk]}],
25
25
  5 => [{:mday => 1, :name => "Sviatok práce", :regions => [:sk]},
@@ -35,9 +35,11 @@ module Holidays
35
35
  {:mday => 26, :name => "2. sviatok vianočný", :regions => [:sk]}]
36
36
  }
37
37
  end
38
- end
39
-
40
38
 
39
+ def self.custom_methods
40
+ {
41
+
42
+ }
43
+ end
44
+ end
41
45
  end
42
-
43
- Holidays.merge_defs(Holidays::SK.defined_regions, Holidays::SK.holidays_by_month)
@@ -10,7 +10,7 @@ module Holidays
10
10
  # require 'holidays'
11
11
  # require 'generated_definitions/united_nations'
12
12
  #
13
- # All the definitions are available at https://github.com/alexdunae/holidays
13
+ # All the definitions are available at https://github.com/holidays/holidays
14
14
  module UNITED_NATIONS # :nodoc:
15
15
  def self.defined_regions
16
16
  [:united_nations]
@@ -77,9 +77,11 @@ module Holidays
77
77
  {:mday => 18, :name => "International Migrants Day", :regions => [:united_nations]}]
78
78
  }
79
79
  end
80
- end
81
-
82
80
 
81
+ def self.custom_methods
82
+ {
83
+
84
+ }
85
+ end
86
+ end
83
87
  end
84
-
85
- Holidays.merge_defs(Holidays::UNITED_NATIONS.defined_regions, Holidays::UNITED_NATIONS.holidays_by_month)
@@ -10,7 +10,7 @@ module Holidays
10
10
  # require 'holidays'
11
11
  # require 'generated_definitions/ups'
12
12
  #
13
- # All the definitions are available at https://github.com/alexdunae/holidays
13
+ # All the definitions are available at https://github.com/holidays/holidays
14
14
  module UPS # :nodoc:
15
15
  def self.defined_regions
16
16
  [:ups]
@@ -18,24 +18,25 @@ module Holidays
18
18
 
19
19
  def self.holidays_by_month
20
20
  {
21
- 1 => [{:mday => 1, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "New Year's Day", :regions => [:ups]}],
21
+ 1 => [{:mday => 1, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "New Year's Day", :regions => [:ups]}],
22
22
  5 => [{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:ups]}],
23
- 7 => [{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Independence Day", :regions => [:ups]}],
23
+ 7 => [{:mday => 4, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Independence Day", :regions => [:ups]}],
24
24
  9 => [{:wday => 1, :week => 1, :name => "Labor Day", :regions => [:ups]}],
25
25
  11 => [{:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:ups]},
26
- {:function => lambda { |year| Holidays.day_after_thanksgiving(year) }, :function_id => "day_after_thanksgiving(year)", :name => "Day After Thanksgiving", :regions => [:ups]}],
27
- 12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Christmas Day", :regions => [:ups]},
26
+ {:function => "day_after_thanksgiving(year)", :function_arguments => [:year], :name => "Day After Thanksgiving", :regions => [:ups]}],
27
+ 12 => [{:mday => 25, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Christmas Day", :regions => [:ups]},
28
28
  {:mday => 31, :name => "New Year's Eve", :regions => [:ups]}]
29
29
  }
30
30
  end
31
- end
32
-
33
- def self.day_after_thanksgiving(year)
34
- Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 11, 4, 4) + 1
35
- end
36
31
 
32
+ def self.custom_methods
33
+ {
34
+ "day_after_thanksgiving(year)" => Proc.new { |year|
35
+ Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 11, 4, 4) + 1
36
+ },
37
37
 
38
38
 
39
+ }
40
+ end
41
+ end
39
42
  end
40
-
41
- Holidays.merge_defs(Holidays::UPS.defined_regions, Holidays::UPS.holidays_by_month)
@@ -10,7 +10,7 @@ module Holidays
10
10
  # require 'holidays'
11
11
  # require 'generated_definitions/us'
12
12
  #
13
- # All the definitions are available at https://github.com/alexdunae/holidays
13
+ # All the definitions are available at https://github.com/holidays/holidays
14
14
  module US # :nodoc:
15
15
  def self.defined_regions
16
16
  [:us, :us_dc, :us_ca, :ca]
@@ -18,11 +18,11 @@ module Holidays
18
18
 
19
19
  def self.holidays_by_month
20
20
  {
21
- 0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :type => :informal, :name => "Good Friday", :regions => [:us]},
22
- {:function => lambda { |year| Holidays.easter(year) }, :function_id => "easter(year)", :type => :informal, :name => "Easter Sunday", :regions => [:us]}],
23
- 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]},
21
+ 0 => [{:function => "easter(year)", :function_arguments => [:year], :function_modifier => -2, :type => :informal, :name => "Good Friday", :regions => [:us]},
22
+ {:function => "easter(year)", :function_arguments => [:year], :type => :informal, :name => "Easter Sunday", :regions => [:us]}],
23
+ 1 => [{:mday => 1, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "New Year's Day", :regions => [:us]},
24
24
  {:wday => 1, :week => 3, :name => "Martin Luther King, Jr. Day", :regions => [:us]},
25
- {:function => lambda { |year| Holidays.us_inauguration_day(year) }, :function_id => "us_inauguration_day(year)", :name => "Inauguration Day", :regions => [:us_dc]}],
25
+ {:function => "us_inauguration_day(year)", :function_arguments => [:year], :name => "Inauguration Day", :regions => [:us_dc]}],
26
26
  2 => [{:wday => 1, :week => 3, :name => "Presidents' Day", :regions => [:us]},
27
27
  {:mday => 2, :type => :informal, :name => "Groundhog Day", :regions => [:us, :ca]},
28
28
  {:mday => 14, :type => :informal, :name => "Valentine's Day", :regions => [:us, :ca]}],
@@ -31,33 +31,32 @@ module Holidays
31
31
  5 => [{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:us]},
32
32
  {:wday => 0, :week => 2, :type => :informal, :name => "Mother's Day", :regions => [:us, :ca]},
33
33
  {:wday => 6, :week => 3, :type => :informal, :name => "Armed Forces Day", :regions => [:us]}],
34
- 7 => [{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Independence Day", :regions => [:us]}],
34
+ 7 => [{:mday => 4, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Independence Day", :regions => [:us]}],
35
35
  9 => [{:wday => 1, :week => 1, :name => "Labor Day", :regions => [:us]}],
36
36
  10 => [{:wday => 1, :week => 2, :name => "Columbus Day", :regions => [:us]},
37
37
  {:mday => 31, :type => :informal, :name => "Halloween", :regions => [:us, :ca]}],
38
- 11 => [{:mday => 11, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Veterans Day", :regions => [:us]},
38
+ 11 => [{:mday => 11, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Veterans Day", :regions => [:us]},
39
39
  {:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:us]},
40
- {:function => lambda { |year| Holidays.day_after_thanksgiving(year) }, :function_id => "day_after_thanksgiving(year)", :name => "Day after Thanksgiving", :regions => [:us_ca]}],
41
- 12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Christmas Day", :regions => [:us]}],
40
+ {:function => "day_after_thanksgiving(year)", :function_arguments => [:year], :name => "Day after Thanksgiving", :regions => [:us_ca]}],
41
+ 12 => [{:mday => 25, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Christmas Day", :regions => [:us]}],
42
42
  4 => [{:mday => 1, :type => :informal, :name => "April Fool's Day", :regions => [:us, :ca]},
43
43
  {:mday => 22, :type => :informal, :name => "Earth Day", :regions => [:us, :ca]}],
44
44
  6 => [{:wday => 0, :week => 3, :type => :informal, :name => "Father's Day", :regions => [:us, :ca]}]
45
45
  }
46
46
  end
47
- end
48
-
49
- # January 20, every fourth year, following Presidential election
50
- def self.us_inauguration_day(year)
51
- year % 4 == 1 ? 20 : nil
52
- end
53
47
 
48
+ def self.custom_methods
49
+ {
50
+ "us_inauguration_day(year)" => Proc.new { |year|
51
+ year % 4 == 1 ? 20 : nil
52
+ },
54
53
 
55
- def self.day_after_thanksgiving(year)
56
- Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 11, 4, 4) + 1
57
- end
58
-
54
+ "day_after_thanksgiving(year)" => Proc.new { |year|
55
+ Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 11, 4, 4) + 1
56
+ },
59
57
 
60
58
 
59
+ }
60
+ end
61
+ end
61
62
  end
62
-
63
- Holidays.merge_defs(Holidays::US.defined_regions, Holidays::US.holidays_by_month)
@@ -10,7 +10,7 @@ module Holidays
10
10
  # require 'holidays'
11
11
  # require 'generated_definitions/ve'
12
12
  #
13
- # All the definitions are available at https://github.com/alexdunae/holidays
13
+ # All the definitions are available at https://github.com/holidays/holidays
14
14
  module VE # :nodoc:
15
15
  def self.defined_regions
16
16
  [:ve]
@@ -18,10 +18,10 @@ module Holidays
18
18
 
19
19
  def self.holidays_by_month
20
20
  {
21
- 0 => [{:function => lambda { |year| Holidays.easter(year)-48 }, :function_id => "easter(year)-48", :name => "Lunes Carnaval", :regions => [:ve]},
22
- {:function => lambda { |year| Holidays.easter(year)-47 }, :function_id => "easter(year)-47", :name => "Martes Carnaval", :regions => [:ve]},
23
- {:function => lambda { |year| Holidays.easter(year)-3 }, :function_id => "easter(year)-3", :name => "Jueves Santo", :regions => [:ve]},
24
- {:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Viernes Santo", :regions => [:ve]}],
21
+ 0 => [{:function => "easter(year)", :function_arguments => [:year], :function_modifier => -48, :name => "Lunes Carnaval", :regions => [:ve]},
22
+ {:function => "easter(year)", :function_arguments => [:year], :function_modifier => -47, :name => "Martes Carnaval", :regions => [:ve]},
23
+ {:function => "easter(year)", :function_arguments => [:year], :function_modifier => -3, :name => "Jueves Santo", :regions => [:ve]},
24
+ {:function => "easter(year)", :function_arguments => [:year], :function_modifier => -2, :name => "Viernes Santo", :regions => [:ve]}],
25
25
  1 => [{:mday => 1, :name => "Año Nuevo", :regions => [:ve]}],
26
26
  4 => [{:mday => 19, :name => "Declaración Independencia", :regions => [:ve]}],
27
27
  5 => [{:mday => 1, :name => "Día del Trabajador", :regions => [:ve]}],
@@ -32,9 +32,11 @@ module Holidays
32
32
  12 => [{:mday => 25, :name => "Día de Navidad", :regions => [:ve]}]
33
33
  }
34
34
  end
35
- end
36
-
37
35
 
36
+ def self.custom_methods
37
+ {
38
+
39
+ }
40
+ end
41
+ end
38
42
  end
39
-
40
- Holidays.merge_defs(Holidays::VE.defined_regions, Holidays::VE.holidays_by_month)
@@ -10,7 +10,7 @@ module Holidays
10
10
  # require 'holidays'
11
11
  # require 'generated_definitions/vi'
12
12
  #
13
- # All the definitions are available at https://github.com/alexdunae/holidays
13
+ # All the definitions are available at https://github.com/holidays/holidays
14
14
  module VI # :nodoc:
15
15
  def self.defined_regions
16
16
  [:vi]
@@ -24,9 +24,11 @@ module Holidays
24
24
  9 => [{:mday => 2, :name => "National Day", :regions => [:vi]}]
25
25
  }
26
26
  end
27
- end
28
-
29
27
 
28
+ def self.custom_methods
29
+ {
30
+
31
+ }
32
+ end
33
+ end
30
34
  end
31
-
32
- Holidays.merge_defs(Holidays::VI.defined_regions, Holidays::VI.holidays_by_month)
@@ -10,7 +10,7 @@ module Holidays
10
10
  # require 'holidays'
11
11
  # require 'generated_definitions/za'
12
12
  #
13
- # All the definitions are available at https://github.com/alexdunae/holidays
13
+ # All the definitions are available at https://github.com/holidays/holidays
14
14
  module ZA # :nodoc:
15
15
  def self.defined_regions
16
16
  [:za]
@@ -18,23 +18,25 @@ module Holidays
18
18
 
19
19
  def self.holidays_by_month
20
20
  {
21
- 0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Good Friday", :regions => [:za]},
22
- {:function => lambda { |year| Holidays.easter(year)+1 }, :function_id => "easter(year)+1", :name => "Family Day", :regions => [:za]}],
23
- 1 => [{:mday => 1, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "New Year's Day", :regions => [:za]}],
24
- 3 => [{:mday => 21, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Human Rights Day", :regions => [:za]}],
25
- 4 => [{:mday => 27, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Freedom Day", :regions => [:za]}],
26
- 5 => [{:mday => 1, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Workers Day", :regions => [:za]}],
27
- 6 => [{:mday => 16, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Youth Day", :regions => [:za]}],
28
- 8 => [{:mday => 9, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "National Women's Day", :regions => [:za]}],
29
- 9 => [{:mday => 24, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Heritage Day", :regions => [:za]}],
30
- 12 => [{:mday => 16, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Day of Reconciliation", :regions => [:za]},
31
- {:mday => 25, :observed => lambda { |date| Holidays.to_monday_if_sunday(date) }, :observed_id => "to_monday_if_sunday", :name => "Christmas Day", :regions => [:za]},
32
- {:mday => 26, :observed => lambda { |date| Holidays.to_weekday_if_boxing_weekend(date) }, :observed_id => "to_weekday_if_boxing_weekend", :name => "Day of Goodwill", :regions => [:za]}]
21
+ 0 => [{:function => "easter(year)", :function_arguments => [:year], :function_modifier => -2, :name => "Good Friday", :regions => [:za]},
22
+ {:function => "easter(year)", :function_arguments => [:year], :function_modifier => 1, :name => "Family Day", :regions => [:za]}],
23
+ 1 => [{:mday => 1, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "New Year's Day", :regions => [:za]}],
24
+ 3 => [{:mday => 21, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Human Rights Day", :regions => [:za]}],
25
+ 4 => [{:mday => 27, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Freedom Day", :regions => [:za]}],
26
+ 5 => [{:mday => 1, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Workers Day", :regions => [:za]}],
27
+ 6 => [{:mday => 16, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Youth Day", :regions => [:za]}],
28
+ 8 => [{:mday => 9, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "National Women's Day", :regions => [:za]}],
29
+ 9 => [{:mday => 24, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Heritage Day", :regions => [:za]}],
30
+ 12 => [{:mday => 16, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Day of Reconciliation", :regions => [:za]},
31
+ {:mday => 25, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Christmas Day", :regions => [:za]},
32
+ {:mday => 26, :observed => "to_weekday_if_boxing_weekend(date)", :observed_arguments => [:date], :name => "Day of Goodwill", :regions => [:za]}]
33
33
  }
34
34
  end
35
- end
36
-
37
35
 
36
+ def self.custom_methods
37
+ {
38
+
39
+ }
40
+ end
41
+ end
38
42
  end
39
-
40
- Holidays.merge_defs(Holidays::ZA.defined_regions, Holidays::ZA.holidays_by_month)
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ ## encoding: utf-8
2
2
  $:.unshift File.dirname(__FILE__)
3
3
 
4
4
  require 'date'
@@ -7,6 +7,8 @@ require 'holidays/definition_factory'
7
7
  require 'holidays/date_calculator_factory'
8
8
  require 'holidays/option_factory'
9
9
  require 'holidays/use_case_factory'
10
+ require 'holidays/errors'
11
+ require 'holidays/load_all_definitions'
10
12
 
11
13
  # == Region options
12
14
  # Holidays can be defined as belonging to one or more regions and sub regions.
@@ -47,9 +49,6 @@ require 'holidays/use_case_factory'
47
49
  #
48
50
  # Holidays.between(from, to, :ca_bc, :informal)
49
51
  module Holidays
50
- # Exception thrown when an unknown region is requested.
51
- class UnknownRegionError < ArgumentError; end
52
-
53
52
  WEEKS = {:first => 1, :second => 2, :third => 3, :fourth => 4, :fifth => 5, :last => -1, :second_last => -2, :third_last => -3}
54
53
  MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
55
54
  DAY_SYMBOLS = Date::DAYNAMES.collect { |n| n.downcase.intern }
@@ -78,7 +77,7 @@ module Holidays
78
77
  #
79
78
  # The given Date can be any day of the week.
80
79
  # Returns true if any holidays fall on Monday - Friday of the given week.
81
- def full_week?(date, *options)
80
+ def any_holidays_during_work_week?(date, *options)
82
81
  days_to_monday = date.wday - 1
83
82
  days_to_friday = 5 - date.wday
84
83
  start_date = date - days_to_monday
@@ -113,7 +112,7 @@ module Holidays
113
112
 
114
113
  start_date, end_date = get_date(start_date), get_date(end_date)
115
114
 
116
- if cached_holidays = DefinitionFactory.cache_repository.find(start_date, end_date, options)
115
+ if cached_holidays = definition_cache_repository.find(start_date, end_date, options)
117
116
  return cached_holidays
118
117
  end
119
118
 
@@ -128,93 +127,25 @@ module Holidays
128
127
  start_date, end_date = get_date(start_date), get_date(end_date)
129
128
  cache_data = between(start_date, end_date, *options)
130
129
 
131
- DefinitionFactory.cache_repository.cache_between(start_date, end_date, cache_data, options)
132
- end
133
-
134
- #TODO This should not be publicly available. I need to restructure the public
135
- # API for this class to something more sensible.
136
- def merge_defs(regions, holidays) # :nodoc:
137
- DefinitionFactory.merger.call(regions, holidays)
138
- end
139
-
140
- def easter(year)
141
- DateCalculatorFactory::Easter::Gregorian.easter_calculator.calculate_easter_for(year)
142
- end
143
-
144
- def orthodox_easter(year)
145
- DateCalculatorFactory::Easter::Gregorian.easter_calculator.calculate_orthodox_easter_for(year)
146
- end
147
-
148
- def orthodox_easter_julian(year)
149
- DateCalculatorFactory::Easter::Julian.easter_calculator.calculate_orthodox_easter_for(year)
150
- end
151
-
152
- def to_monday_if_sunday(date)
153
- DateCalculatorFactory.weekend_modifier.to_monday_if_sunday(date)
154
- end
155
-
156
- def to_monday_if_weekend(date)
157
- DateCalculatorFactory.weekend_modifier.to_monday_if_weekend(date)
158
- end
159
-
160
- def to_weekday_if_boxing_weekend(date)
161
- DateCalculatorFactory.weekend_modifier.to_weekday_if_boxing_weekend(date)
162
- end
163
-
164
- def to_tuesday_if_sunday_or_monday_if_saturday(year)
165
- DateCalculatorFactory.weekend_modifier.to_tuesday_if_sunday_or_monday_if_saturday(year)
166
- end
167
-
168
- def xmas_to_weekday_if_weekend(year)
169
- DateCalculatorFactory.weekend_modifier.xmas_to_weekday_if_weekend(year)
170
- end
171
-
172
- def to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(year)
173
- DateCalculatorFactory.weekend_modifier.to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(year)
174
- end
175
-
176
- def to_weekday_if_boxing_weekend_from_year(year)
177
- DateCalculatorFactory.weekend_modifier.to_weekday_if_boxing_weekend_from_year(year)
178
- end
179
-
180
- def to_weekday_if_weekend(date)
181
- DateCalculatorFactory.weekend_modifier.to_weekday_if_weekend(date)
182
- end
183
-
184
- def calculate_day_of_month(year, month, day, wday)
185
- DateCalculatorFactory.day_of_month_calculator.call(year, month, day, wday)
186
- end
187
-
188
- # Returns an array of symbols all the available holiday definitions.
189
- #
190
- # Optional `full_path` param is used internally for loading all the definitions.
191
- def available(full_path = false)
192
- paths = Dir.glob(FULL_DEFINITIONS_PATH + '/*.rb')
193
- full_path ? paths : paths.collect { |path| path.match(/([a-z_-]+)\.rb/i)[1].to_sym }
130
+ definition_cache_repository.cache_between(start_date, end_date, cache_data, options)
194
131
  end
195
132
 
196
133
  # Returns an array of symbols of all the available holiday regions.
197
- def regions
198
- DefinitionFactory.regions_repository.all
199
- end
200
-
201
- # Load all available holiday definitions
202
- def load_all
203
- available(true).each { |path| require path }
134
+ def available_regions
135
+ Holidays::REGIONS
204
136
  end
205
137
 
206
138
  # Parses provided holiday definition file(s) and loads them so that they are immediately available.
207
139
  def load_custom(*files)
208
140
  regions, rules_by_month, custom_methods, tests = DefinitionFactory.file_parser.parse_definition_files(files)
209
- merge_defs(regions, rules_by_month)
210
- end
211
141
 
212
- # Parses provided holiday definition file(s) and returns strings containing the generated module and test source
213
- def parse_definition_files_and_return_source(module_name, *files)
214
- regions, rules_by_month, custom_methods, tests = DefinitionFactory.file_parser.parse_definition_files(files)
215
- module_src, test_src = DefinitionFactory.source_generator.generate_definition_source(module_name, files, regions, rules_by_month, custom_methods, tests)
142
+ custom_methods.each do |method_key, method_entity|
143
+ custom_methods[method_key] = Holidays::DefinitionFactory.custom_method_proc_decorator.call(method_entity)
144
+ end
216
145
 
217
- return module_src, test_src, regions
146
+ DefinitionFactory.merger.call(regions, rules_by_month, custom_methods)
147
+
148
+ rules_by_month
218
149
  end
219
150
 
220
151
  private
@@ -226,5 +157,11 @@ module Holidays
226
157
  Date.civil(date.year, date.mon, date.mday)
227
158
  end
228
159
  end
160
+
161
+ def definition_cache_repository
162
+ DefinitionFactory.cache_repository
163
+ end
229
164
  end
230
165
  end
166
+
167
+ Holidays::LoadAllDefinitions.call