holidays 4.2.0 → 8.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (330) hide show
  1. checksums.yaml +5 -5
  2. data/.gitmodules +3 -0
  3. data/CHANGELOG.md +195 -0
  4. data/Makefile +45 -0
  5. data/README.md +253 -77
  6. data/Rakefile +10 -11
  7. data/bin/console +0 -0
  8. data/bin/setup +1 -0
  9. data/doc/CONTRIBUTING.md +72 -0
  10. data/doc/MAINTAINERS.md +81 -0
  11. data/{REFERENCES → doc/REFERENCES} +0 -0
  12. data/holidays.gemspec +9 -9
  13. data/lib/generated_definitions/MANIFEST +26 -4
  14. data/lib/generated_definitions/REGIONS.rb +3 -1
  15. data/lib/generated_definitions/ar.rb +4 -10
  16. data/lib/generated_definitions/at.rb +3 -9
  17. data/lib/generated_definitions/au.rb +32 -25
  18. data/lib/generated_definitions/be_fr.rb +2 -8
  19. data/lib/generated_definitions/be_nl.rb +2 -8
  20. data/lib/generated_definitions/bg.rb +2 -8
  21. data/lib/generated_definitions/br.rb +2 -8
  22. data/lib/generated_definitions/ca.rb +33 -32
  23. data/lib/generated_definitions/ch.rb +17 -11
  24. data/lib/generated_definitions/cl.rb +38 -12
  25. data/lib/generated_definitions/co.rb +121 -0
  26. data/lib/generated_definitions/cr.rb +2 -8
  27. data/lib/generated_definitions/cz.rb +2 -8
  28. data/lib/generated_definitions/de.rb +11 -14
  29. data/lib/generated_definitions/dk.rb +2 -8
  30. data/lib/generated_definitions/{ecb_target.rb → ecbtarget.rb} +10 -16
  31. data/lib/generated_definitions/ee.rb +36 -0
  32. data/lib/generated_definitions/el.rb +2 -8
  33. data/lib/generated_definitions/es.rb +8 -11
  34. data/lib/generated_definitions/europe.rb +121 -51
  35. data/lib/generated_definitions/federalreserve.rb +34 -0
  36. data/lib/generated_definitions/{federal_reserve.rb → federalreservebanks.rb} +14 -20
  37. data/lib/generated_definitions/fedex.rb +3 -9
  38. data/lib/generated_definitions/fi.rb +2 -8
  39. data/lib/generated_definitions/fr.rb +6 -10
  40. data/lib/generated_definitions/gb.rb +12 -16
  41. data/lib/generated_definitions/ge.rb +41 -0
  42. data/lib/generated_definitions/hk.rb +106 -0
  43. data/lib/generated_definitions/hr.rb +10 -14
  44. data/lib/generated_definitions/hu.rb +4 -9
  45. data/lib/generated_definitions/ie.rb +3 -17
  46. data/lib/generated_definitions/is.rb +3 -9
  47. data/lib/generated_definitions/it.rb +16 -13
  48. data/lib/generated_definitions/jp.rb +47 -36
  49. data/lib/generated_definitions/kr.rb +40 -0
  50. data/lib/generated_definitions/kz.rb +38 -0
  51. data/lib/generated_definitions/li.rb +2 -8
  52. data/lib/generated_definitions/lt.rb +2 -8
  53. data/lib/generated_definitions/lu.rb +35 -0
  54. data/lib/generated_definitions/lv.rb +52 -0
  55. data/lib/generated_definitions/ma.rb +2 -8
  56. data/lib/generated_definitions/mt_en.rb +38 -0
  57. data/lib/generated_definitions/mt_mt.rb +38 -0
  58. data/lib/generated_definitions/mx.rb +6 -12
  59. data/lib/generated_definitions/my.rb +30 -0
  60. data/lib/generated_definitions/nerc.rb +2 -8
  61. data/lib/generated_definitions/ng.rb +33 -0
  62. data/lib/generated_definitions/nl.rb +2 -8
  63. data/lib/generated_definitions/no.rb +2 -8
  64. data/lib/generated_definitions/northamerica.rb +223 -0
  65. data/lib/generated_definitions/nyse.rb +3 -9
  66. data/lib/generated_definitions/nz.rb +2 -9
  67. data/lib/generated_definitions/pe.rb +43 -0
  68. data/lib/generated_definitions/ph.rb +4 -10
  69. data/lib/generated_definitions/pl.rb +2 -8
  70. data/lib/generated_definitions/pt.rb +12 -12
  71. data/lib/generated_definitions/ro.rb +6 -9
  72. data/lib/generated_definitions/rs_cyrl.rb +39 -0
  73. data/lib/generated_definitions/rs_la.rb +39 -0
  74. data/lib/generated_definitions/ru.rb +37 -0
  75. data/lib/generated_definitions/scandinavia.rb +3 -9
  76. data/lib/generated_definitions/se.rb +2 -8
  77. data/lib/generated_definitions/sg.rb +2 -8
  78. data/lib/generated_definitions/si.rb +2 -8
  79. data/lib/generated_definitions/sk.rb +2 -8
  80. data/lib/generated_definitions/southamerica.rb +228 -0
  81. data/lib/generated_definitions/th.rb +36 -0
  82. data/lib/generated_definitions/tn.rb +32 -0
  83. data/lib/generated_definitions/tr.rb +64 -0
  84. data/lib/generated_definitions/ua.rb +37 -0
  85. data/lib/generated_definitions/{united_nations.rb → unitednations.rb} +61 -67
  86. data/lib/generated_definitions/ups.rb +3 -9
  87. data/lib/generated_definitions/us.rb +113 -23
  88. data/lib/generated_definitions/ve.rb +2 -8
  89. data/lib/generated_definitions/vi.rb +6 -11
  90. data/lib/generated_definitions/za.rb +2 -8
  91. data/lib/holidays/core_extensions/date.rb +21 -3
  92. data/lib/holidays/core_extensions/time.rb +23 -0
  93. data/lib/holidays/date_calculator/day_of_month.rb +3 -3
  94. data/lib/holidays/date_calculator/lunar_date.rb +371 -0
  95. data/lib/holidays/date_calculator/weekend_modifier.rb +0 -7
  96. data/lib/holidays/definition/context/function_processor.rb +91 -0
  97. data/lib/holidays/definition/context/generator.rb +37 -96
  98. data/lib/holidays/definition/context/load.rb +29 -0
  99. data/lib/holidays/definition/context/merger.rb +0 -4
  100. data/lib/holidays/definition/decorator/test.rb +37 -0
  101. data/lib/holidays/definition/entity/test.rb +11 -0
  102. data/lib/holidays/definition/generator/module.rb +54 -0
  103. data/lib/holidays/definition/generator/regions.rb +55 -0
  104. data/lib/holidays/definition/generator/test.rb +51 -0
  105. data/lib/holidays/definition/parser/custom_method.rb +3 -5
  106. data/lib/holidays/definition/parser/test.rb +86 -0
  107. data/lib/holidays/definition/repository/cache.rb +23 -9
  108. data/lib/holidays/definition/repository/holidays_by_month.rb +10 -2
  109. data/lib/holidays/definition/repository/proc_result_cache.rb +1 -1
  110. data/lib/holidays/definition/repository/regions.rb +23 -13
  111. data/lib/holidays/definition/validator/custom_method.rb +1 -1
  112. data/lib/holidays/definition/validator/region.rb +2 -11
  113. data/lib/holidays/definition/validator/test.rb +71 -0
  114. data/lib/holidays/errors.rb +5 -0
  115. data/lib/holidays/factory/date_calculator.rb +42 -0
  116. data/lib/holidays/factory/definition.rb +143 -0
  117. data/lib/holidays/factory/finder.rb +70 -0
  118. data/lib/holidays/finder/context/between.rb +45 -0
  119. data/lib/holidays/{use_case → finder}/context/dates_driver_builder.rb +11 -15
  120. data/lib/holidays/finder/context/next_holiday.rb +57 -0
  121. data/lib/holidays/finder/context/parse_options.rb +104 -0
  122. data/lib/holidays/finder/context/search.rb +110 -0
  123. data/lib/holidays/finder/context/year_holiday.rb +57 -0
  124. data/lib/holidays/finder/rules/in_region.rb +31 -0
  125. data/lib/holidays/finder/rules/year_range.rb +58 -0
  126. data/lib/holidays/load_all_definitions.rb +16 -17
  127. data/lib/holidays/version.rb +1 -1
  128. data/lib/holidays.rb +50 -125
  129. data/test/coverage_report.rb +26 -0
  130. data/test/data/test_custom_informal_holidays_defs.yaml +11 -0
  131. data/test/data/test_custom_year_range_holiday_defs.yaml +13 -10
  132. data/test/data/test_invalid_region.rb +15 -0
  133. data/test/data/test_multiple_custom_holiday_defs.yaml +7 -4
  134. data/test/data/test_multiple_regions_with_conflicts_region_1.yaml +38 -0
  135. data/test/data/test_multiple_regions_with_conflicts_region_2.yaml +38 -0
  136. data/test/data/test_region.rb +15 -0
  137. data/test/data/test_single_custom_holiday_defs.yaml +7 -4
  138. data/test/data/test_single_custom_holiday_with_custom_procs.yaml +11 -7
  139. data/test/defs/test_defs_ar.rb +41 -19
  140. data/test/defs/test_defs_at.rb +18 -11
  141. data/test/defs/test_defs_au.rb +185 -126
  142. data/test/defs/test_defs_be_fr.rb +33 -14
  143. data/test/defs/test_defs_be_nl.rb +33 -14
  144. data/test/defs/test_defs_bg.rb +29 -17
  145. data/test/defs/test_defs_br.rb +33 -19
  146. data/test/defs/test_defs_ca.rb +246 -136
  147. data/test/defs/test_defs_ch.rb +35 -23
  148. data/test/defs/test_defs_cl.rb +57 -27
  149. data/test/defs/test_defs_co.rb +113 -0
  150. data/test/defs/test_defs_cr.rb +17 -11
  151. data/test/defs/test_defs_cz.rb +25 -15
  152. data/test/defs/test_defs_de.rb +60 -59
  153. data/test/defs/test_defs_dk.rb +31 -19
  154. data/test/defs/test_defs_ecbtarget.rb +27 -0
  155. data/test/defs/test_defs_ee.rb +41 -0
  156. data/test/defs/test_defs_el.rb +29 -17
  157. data/test/defs/test_defs_es.rb +116 -52
  158. data/test/defs/test_defs_europe.rb +1382 -701
  159. data/test/defs/test_defs_federalreserve.rb +113 -0
  160. data/test/defs/test_defs_federalreservebanks.rb +247 -0
  161. data/test/defs/test_defs_fedex.rb +19 -12
  162. data/test/defs/test_defs_fi.rb +47 -27
  163. data/test/defs/test_defs_fr.rb +31 -18
  164. data/test/defs/test_defs_gb.rb +120 -51
  165. data/test/defs/test_defs_ge.rb +53 -0
  166. data/test/defs/test_defs_hk.rb +59 -0
  167. data/test/defs/test_defs_hr.rb +32 -18
  168. data/test/defs/test_defs_hu.rb +34 -16
  169. data/test/defs/test_defs_ie.rb +41 -25
  170. data/test/defs/test_defs_is.rb +39 -22
  171. data/test/defs/test_defs_it.rb +43 -14
  172. data/test/defs/test_defs_jp.rb +141 -55
  173. data/test/defs/test_defs_kr.rb +37 -0
  174. data/test/defs/test_defs_kz.rb +39 -0
  175. data/test/defs/test_defs_li.rb +20 -20
  176. data/test/defs/test_defs_lt.rb +51 -30
  177. data/test/defs/test_defs_lu.rb +35 -0
  178. data/test/defs/test_defs_lv.rb +90 -0
  179. data/test/defs/test_defs_ma.rb +17 -11
  180. data/test/defs/test_defs_mt_en.rb +41 -0
  181. data/test/defs/test_defs_mt_mt.rb +41 -0
  182. data/test/defs/test_defs_mx.rb +34 -23
  183. data/test/defs/test_defs_my.rb +23 -0
  184. data/test/defs/test_defs_nerc.rb +17 -11
  185. data/test/defs/test_defs_ng.rb +29 -0
  186. data/test/defs/test_defs_nl.rb +21 -13
  187. data/test/defs/test_defs_no.rb +31 -18
  188. data/test/defs/test_defs_northamerica.rb +644 -0
  189. data/test/defs/test_defs_nyse.rb +27 -11
  190. data/test/defs/test_defs_nz.rb +47 -28
  191. data/test/defs/test_defs_pe.rb +47 -0
  192. data/test/defs/test_defs_ph.rb +17 -13
  193. data/test/defs/test_defs_pl.rb +200 -119
  194. data/test/defs/test_defs_pt.rb +35 -15
  195. data/test/defs/test_defs_ro.rb +53 -24
  196. data/test/defs/test_defs_rs_cyrl.rb +46 -0
  197. data/test/defs/test_defs_rs_la.rb +46 -0
  198. data/test/defs/test_defs_ru.rb +34 -0
  199. data/test/defs/test_defs_scandinavia.rb +193 -116
  200. data/test/defs/test_defs_se.rb +47 -28
  201. data/test/defs/test_defs_sg.rb +13 -9
  202. data/test/defs/test_defs_si.rb +93 -24
  203. data/test/defs/test_defs_sk.rb +29 -17
  204. data/test/defs/test_defs_southamerica.rb +307 -0
  205. data/test/defs/test_defs_th.rb +33 -0
  206. data/test/defs/test_defs_tn.rb +27 -0
  207. data/test/defs/test_defs_tr.rb +60 -0
  208. data/test/defs/test_defs_ua.rb +41 -0
  209. data/test/defs/{test_defs_united_nations.rb → test_defs_unitednations.rb} +3 -4
  210. data/test/defs/test_defs_ups.rb +19 -12
  211. data/test/defs/test_defs_us.rb +370 -30
  212. data/test/defs/test_defs_ve.rb +23 -16
  213. data/test/defs/test_defs_vi.rb +10 -6
  214. data/test/defs/test_defs_za.rb +23 -14
  215. data/test/holidays/core_extensions/test_date.rb +3 -2
  216. data/test/holidays/core_extensions/test_date_time.rb +60 -0
  217. data/test/holidays/date_calculator/test_lunar_date.rb +89 -0
  218. data/test/holidays/definition/context/test_function_processor.rb +199 -0
  219. data/test/holidays/definition/context/test_generator.rb +66 -35
  220. data/test/holidays/definition/context/test_load.rb +37 -0
  221. data/test/holidays/definition/decorator/test_test.rb +123 -0
  222. data/test/holidays/definition/generator/test_module.rb +268 -0
  223. data/test/holidays/definition/generator/test_regions.rb +97 -0
  224. data/test/holidays/definition/generator/test_test.rb +113 -0
  225. data/test/holidays/definition/parser/test_custom_method.rb +6 -6
  226. data/test/holidays/definition/parser/test_test.rb +142 -0
  227. data/test/holidays/definition/repository/test_cache.rb +47 -6
  228. data/test/holidays/definition/repository/test_holidays_by_month.rb +121 -1
  229. data/test/holidays/definition/repository/test_proc_result_cache.rb +8 -1
  230. data/test/holidays/definition/repository/test_regions.rb +31 -13
  231. data/test/holidays/definition/validator/test_custom_method.rb +5 -0
  232. data/test/holidays/definition/validator/test_region.rb +16 -12
  233. data/test/holidays/definition/validator/test_test.rb +60 -0
  234. data/test/holidays/finder/context/test_between.rb +172 -0
  235. data/test/holidays/{use_case → finder}/context/test_dates_driver_builder.rb +2 -2
  236. data/test/holidays/finder/context/test_next_holiday.rb +156 -0
  237. data/test/holidays/finder/context/test_parse_options.rb +141 -0
  238. data/test/holidays/finder/context/test_search.rb +232 -0
  239. data/test/holidays/finder/context/test_year_holiday.rb +202 -0
  240. data/test/holidays/finder/rules/test_in_region.rb +42 -0
  241. data/test/holidays/finder/rules/test_year_range.rb +166 -0
  242. data/test/integration/README.md +9 -0
  243. data/test/{test_all_regions.rb → integration/test_all_regions.rb} +18 -4
  244. data/test/integration/test_any_holidays_during_work_week.rb +90 -0
  245. data/test/integration/test_available_regions.rb +23 -0
  246. data/test/{test_custom_holidays.rb → integration/test_custom_holidays.rb} +6 -6
  247. data/test/integration/test_custom_informal_holidays.rb +15 -0
  248. data/test/{test_custom_year_range_holidays.rb → integration/test_custom_year_range_holidays.rb} +1 -9
  249. data/test/{test_holidays.rb → integration/test_holidays.rb} +100 -69
  250. data/test/{test_holidays_between.rb → integration/test_holidays_between.rb} +19 -17
  251. data/test/integration/test_multiple_regions.rb +71 -0
  252. data/test/integration/test_multiple_regions_with_conflict.rb +29 -0
  253. data/test/integration/test_nonstandard_regions.rb +25 -0
  254. data/test/test_helper.rb +7 -3
  255. metadata +204 -132
  256. data/CONTRIBUTING.md +0 -41
  257. data/benchmark.rb +0 -8
  258. data/definitions/README.md +0 -353
  259. data/definitions/ar.yaml +0 -93
  260. data/definitions/at.yaml +0 -72
  261. data/definitions/au.yaml +0 -375
  262. data/definitions/be_fr.yaml +0 -69
  263. data/definitions/be_nl.yaml +0 -69
  264. data/definitions/bg.yaml +0 -127
  265. data/definitions/br.yaml +0 -77
  266. data/definitions/ca.yaml +0 -302
  267. data/definitions/ch.yaml +0 -193
  268. data/definitions/cl.yaml +0 -94
  269. data/definitions/cr.yaml +0 -65
  270. data/definitions/cz.yaml +0 -73
  271. data/definitions/de.yaml +0 -209
  272. data/definitions/dk.yaml +0 -130
  273. data/definitions/ecb_target.yaml +0 -44
  274. data/definitions/el.yaml +0 -84
  275. data/definitions/es.yaml +0 -203
  276. data/definitions/federal_reserve.yaml +0 -114
  277. data/definitions/fedex.yaml +0 -62
  278. data/definitions/fi.yaml +0 -115
  279. data/definitions/fr.yaml +0 -79
  280. data/definitions/gb.yaml +0 -151
  281. data/definitions/hr.yaml +0 -79
  282. data/definitions/hu.yaml +0 -63
  283. data/definitions/ie.yaml +0 -89
  284. data/definitions/index.yaml +0 -57
  285. data/definitions/is.yaml +0 -146
  286. data/definitions/it.yaml +0 -67
  287. data/definitions/jp.yaml +0 -316
  288. data/definitions/li.yaml +0 -107
  289. data/definitions/lt.yaml +0 -89
  290. data/definitions/ma.yaml +0 -52
  291. data/definitions/mx.yaml +0 -106
  292. data/definitions/nerc.yaml +0 -51
  293. data/definitions/nl.yaml +0 -73
  294. data/definitions/no.yaml +0 -90
  295. data/definitions/north_america_informal.yaml +0 -61
  296. data/definitions/nyse.yaml +0 -64
  297. data/definitions/nz.yaml +0 -163
  298. data/definitions/ph.yaml +0 -94
  299. data/definitions/pl.yaml +0 -320
  300. data/definitions/pt.yaml +0 -69
  301. data/definitions/ro.yaml +0 -78
  302. data/definitions/se.yaml +0 -120
  303. data/definitions/sg.yaml +0 -56
  304. data/definitions/si.yaml +0 -86
  305. data/definitions/sk.yaml +0 -80
  306. data/definitions/united_nations.yaml +0 -189
  307. data/definitions/ups.yaml +0 -62
  308. data/definitions/us.yaml +0 -103
  309. data/definitions/ve.yaml +0 -74
  310. data/definitions/vi.yaml +0 -29
  311. data/definitions/za.yaml +0 -80
  312. data/lib/generated_definitions/north_america.rb +0 -126
  313. data/lib/holidays/date_calculator_factory.rb +0 -35
  314. data/lib/holidays/definition_factory.rb +0 -86
  315. data/lib/holidays/option/context/parse_options.rb +0 -106
  316. data/lib/holidays/option_factory.rb +0 -15
  317. data/lib/holidays/use_case/context/between.rb +0 -45
  318. data/lib/holidays/use_case/context/context_common.rb +0 -123
  319. data/lib/holidays/use_case/context/next_holiday.rb +0 -54
  320. data/lib/holidays/use_case_factory.rb +0 -31
  321. data/test/defs/test_defs_ecb_target.rb +0 -23
  322. data/test/defs/test_defs_federal_reserve.rb +0 -69
  323. data/test/defs/test_defs_north_america.rb +0 -195
  324. data/test/holidays/option/context/test_parse_options.rb +0 -74
  325. data/test/holidays/test_date_calculator_factory.rb +0 -27
  326. data/test/holidays/test_definition_factory.rb +0 -49
  327. data/test/holidays/test_option_factory.rb +0 -9
  328. data/test/holidays/test_use_case_factory.rb +0 -13
  329. data/test/holidays/use_case/context/test_between.rb +0 -77
  330. data/test/test_multiple_regions.rb +0 -24
@@ -1,126 +0,0 @@
1
- # encoding: utf-8
2
- module Holidays
3
- # This file is generated by the Ruby Holidays gem.
4
- #
5
- # Definitions loaded: definitions/ca.yaml, definitions/mx.yaml, definitions/us.yaml, definitions/north_america_informal.yaml
6
- #
7
- # To use the definitions in this file, load it right after you load the
8
- # Holiday gem:
9
- #
10
- # require 'holidays'
11
- # require 'generated_definitions/north_america'
12
- #
13
- # All the definitions are available at https://github.com/holidays/holidays
14
- module NORTH_AMERICA # :nodoc:
15
- def self.defined_regions
16
- [:ca, :ca_qc, :ca_ab, :ca_sk, :ca_on, :ca_bc, :ca_mb, :ca_ns, :ca_pe, :ca_nf, :ca_nt, :ca_nu, :ca_nb, :ca_yk, :mx, :mx_pue, :us, :us_dc, :us_ca]
17
- end
18
-
19
- def self.holidays_by_month
20
- {
21
- 0 => [{:function => "easter(year)", :function_arguments => [:year], :function_modifier => -2, :name => "Good Friday", :regions => [:ca]},
22
- {:function => "easter(year)", :function_arguments => [:year], :name => "Easter Sunday", :regions => [:ca]},
23
- {:function => "easter(year)", :function_arguments => [:year], :function_modifier => 1, :type => :informal, :name => "Easter Monday", :regions => [:ca]},
24
- {:function => "easter(year)", :function_arguments => [:year], :function_modifier => -2, :type => :informal, :name => "Good Friday", :regions => [:us]},
25
- {:function => "easter(year)", :function_arguments => [:year], :type => :informal, :name => "Easter Sunday", :regions => [:us]}],
26
- 1 => [{:mday => 1, :name => "New Year's Day", :regions => [:ca]},
27
- {:mday => 2, :name => "New Year's", :regions => [:ca_qc]},
28
- {:mday => 1, :name => "Año nuevo", :regions => [:mx]},
29
- {:mday => 6, :name => "Dia de los Santos Reyes", :regions => [:mx]},
30
- {:mday => 1, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "New Year's Day", :regions => [:us]},
31
- {:wday => 1, :week => 3, :name => "Martin Luther King, Jr. Day", :regions => [:us]},
32
- {:function => "us_inauguration_day(year)", :function_arguments => [:year], :name => "Inauguration Day", :regions => [:us_dc]}],
33
- 2 => [{:wday => 1, :week => 3, :year_ranges => [{:after => 1990}],:name => "Family Day", :regions => [:ca_ab]},
34
- {:wday => 1, :week => 3, :year_ranges => [{:after => 2007}],:name => "Family Day", :regions => [:ca_sk]},
35
- {:wday => 1, :week => 3, :year_ranges => [{:after => 2008}],:name => "Family Day", :regions => [:ca_on]},
36
- {:wday => 1, :week => 2, :year_ranges => [{:after => 2013}],:name => "Family Day", :regions => [:ca_bc]},
37
- {:wday => 1, :week => 3, :name => "Louis Riel Day", :regions => [:ca_mb]},
38
- {:wday => 1, :week => 3, :year_ranges => [{:after => 2015}],:name => "Nova Scotia Heritage Day", :regions => [:ca_ns]},
39
- {:wday => 1, :week => 3, :name => "Islander Day", :regions => [:ca_pe]},
40
- {:wday => 1, :week => 1, :name => "Día de la Constitución", :regions => [:mx]},
41
- {:wday => 1, :week => 3, :name => "Presidents' Day", :regions => [:us]},
42
- {:mday => 2, :type => :informal, :name => "Groundhog Day", :regions => [:us, :ca]},
43
- {:mday => 14, :type => :informal, :name => "Valentine's Day", :regions => [:us, :ca]}],
44
- 3 => [{:mday => 23, :name => "St. George's Day", :regions => [:ca_nf]},
45
- {:wday => 1, :week => 3, :name => "Natalicio de Benito Juárez", :regions => [:mx]},
46
- {:mday => 31, :name => "Cesar Chavez Day", :regions => [:us_ca]},
47
- {:mday => 17, :type => :informal, :name => "St. Patrick's Day", :regions => [:us, :ca]}],
48
- 5 => [{:function => "ca_victoria_day(year)", :function_arguments => [:year], :name => "Victoria Day", :regions => [:ca]},
49
- {:function => "ca_victoria_day(year)", :function_arguments => [:year], :name => "National Patriotes Day", :regions => [:ca_qc]},
50
- {:mday => 1, :name => "Día del Trabajo", :regions => [:mx]},
51
- {:mday => 5, :type => :informal, :name => "Cinco de Mayo", :regions => [:mx]},
52
- {:mday => 5, :name => "La Batalla de Puebla", :regions => [:mx_pue]},
53
- {:mday => 10, :type => :informal, :name => "Día de la Madre", :regions => [:mx]},
54
- {:mday => 15, :type => :informal, :name => "Día del Maestro", :regions => [:mx]},
55
- {:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:us]},
56
- {:wday => 0, :week => 2, :type => :informal, :name => "Mother's Day", :regions => [:us, :ca]},
57
- {:wday => 6, :week => 3, :type => :informal, :name => "Armed Forces Day", :regions => [:us]}],
58
- 6 => [{:mday => 24, :name => "Discovery Day", :regions => [:ca_nf]},
59
- {:mday => 24, :name => "Fête Nationale", :regions => [:ca_qc]},
60
- {:mday => 21, :name => "National Aboriginal Day", :regions => [:ca_nt]},
61
- {:wday => 0, :week => 3, :type => :informal, :name => "Día del Padre", :regions => [:mx]},
62
- {:wday => 0, :week => 3, :type => :informal, :name => "Father's Day", :regions => [:us, :ca]}],
63
- 7 => [{:mday => 1, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Canada Day", :regions => [:ca]},
64
- {:mday => 12, :name => "Orangemen's Day", :regions => [:ca_nf]},
65
- {:mday => 9, :name => "Nunavut Day", :regions => [:ca_nu]},
66
- {:mday => 4, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Independence Day", :regions => [:us]}],
67
- 8 => [{:wday => 1, :week => 1, :name => "BC Day", :regions => [:ca_bc]},
68
- {:wday => 1, :week => 1, :name => "Saskatchewan Day", :regions => [:ca_sk]},
69
- {:wday => 1, :week => 1, :name => "Heritage Day", :regions => [:ca_ab]},
70
- {:wday => 1, :week => 1, :name => "Natal Day", :regions => [:ca_ns]},
71
- {:wday => 1, :week => 1, :name => "Civic Holiday", :regions => [:ca_on, :ca_nt, :ca_nu, :ca_pe]},
72
- {:wday => 1, :week => 1, :name => "New Brunswick Day", :regions => [:ca_nb]},
73
- {:wday => 1, :week => 3, :name => "Discovery Day", :regions => [:ca_yk]}],
74
- 9 => [{:wday => 1, :week => 1, :name => "Labour Day", :regions => [:ca]},
75
- {:mday => 15, :name => "Grito de Dolores", :regions => [:mx]},
76
- {:mday => 16, :name => "Día de la Independencia", :regions => [:mx]},
77
- {:wday => 1, :week => 1, :name => "Labor Day", :regions => [:us]}],
78
- 10 => [{:wday => 1, :week => 2, :name => "Thanksgiving", :regions => [:ca]},
79
- {:mday => 12, :type => :informal, :name => "Día de la Raza", :regions => [:mx]},
80
- {:wday => 1, :week => 2, :name => "Columbus Day", :regions => [:us]},
81
- {:mday => 31, :type => :informal, :name => "Halloween", :regions => [:us, :ca]}],
82
- 11 => [{:mday => 11, :name => "Remembrance Day", :regions => [:ca]},
83
- {:mday => 1, :type => :informal, :name => "Todos los Santos", :regions => [:mx]},
84
- {:mday => 2, :type => :informal, :name => "Los Fieles Difuntos", :regions => [:mx]},
85
- {:wday => 1, :week => 3, :name => "Día de la Revolución", :regions => [:mx]},
86
- {:mday => 11, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Veterans Day", :regions => [:us]},
87
- {:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:us]},
88
- {:function => "day_after_thanksgiving(year)", :function_arguments => [:year], :name => "Day after Thanksgiving", :regions => [:us_ca]}],
89
- 12 => [{:mday => 25, :name => "Christmas Day", :regions => [:ca]},
90
- {:mday => 26, :name => "Boxing Day", :regions => [:ca]},
91
- {:mday => 12, :type => :informal, :name => "Día de la Virgen de Guadalupe", :regions => [:mx]},
92
- {:mday => 24, :type => :informal, :name => "Nochebuena", :regions => [:mx]},
93
- {:mday => 25, :name => "Navidad", :regions => [:mx]},
94
- {:mday => 28, :name => "Los Santos Inocentes", :regions => [:mx]},
95
- {:mday => 25, :observed => "to_weekday_if_weekend(date)", :observed_arguments => [:date], :name => "Christmas Day", :regions => [:us]}],
96
- 4 => [{:mday => 30, :type => :informal, :name => "Día del Niño", :regions => [:mx]},
97
- {:mday => 1, :type => :informal, :name => "April Fool's Day", :regions => [:us, :ca]},
98
- {:mday => 22, :type => :informal, :name => "Earth Day", :regions => [:us, :ca]}]
99
- }
100
- end
101
-
102
- def self.custom_methods
103
- {
104
- "ca_victoria_day(year)" => Proc.new { |year|
105
- date = Date.civil(year,5,24)
106
- if date.wday > 1
107
- date -= (date.wday - 1)
108
- elsif date.wday == 0
109
- date -= 6
110
- end
111
- date
112
- },
113
-
114
- "us_inauguration_day(year)" => Proc.new { |year|
115
- year % 4 == 1 ? 20 : nil
116
- },
117
-
118
- "day_after_thanksgiving(year)" => Proc.new { |year|
119
- Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 11, 4, 4) + 1
120
- },
121
-
122
-
123
- }
124
- end
125
- end
126
- end
@@ -1,35 +0,0 @@
1
- require 'holidays/date_calculator/easter'
2
- require 'holidays/date_calculator/weekend_modifier'
3
- require 'holidays/date_calculator/day_of_month'
4
-
5
- module Holidays
6
- module DateCalculatorFactory
7
- module Easter
8
- module Gregorian
9
- class << self
10
- def easter_calculator
11
- DateCalculator::Easter::Gregorian.new
12
- end
13
- end
14
- end
15
-
16
- module Julian
17
- class << self
18
- def easter_calculator
19
- DateCalculator::Easter::Julian.new
20
- end
21
- end
22
- end
23
- end
24
-
25
- class << self
26
- def weekend_modifier
27
- DateCalculator::WeekendModifier.new
28
- end
29
-
30
- def day_of_month_calculator
31
- DateCalculator::DayOfMonth.new
32
- end
33
- end
34
- end
35
- end
@@ -1,86 +0,0 @@
1
- require 'holidays/definition/context/generator'
2
- require 'holidays/definition/context/merger'
3
- require 'holidays/definition/decorator/custom_method_proc'
4
- require 'holidays/definition/decorator/custom_method_source'
5
- require 'holidays/definition/parser/custom_method'
6
- require 'holidays/definition/repository/holidays_by_month'
7
- require 'holidays/definition/repository/regions'
8
- require 'holidays/definition/repository/cache'
9
- require 'holidays/definition/repository/proc_result_cache'
10
- require 'holidays/definition/repository/custom_methods'
11
- require 'holidays/definition/validator/custom_method'
12
- require 'holidays/definition/validator/region'
13
-
14
- module Holidays
15
- module DefinitionFactory
16
- class << self
17
- def file_parser
18
- Definition::Context::Generator.new(
19
- custom_method_parser,
20
- custom_method_source_decorator,
21
- custom_methods_repository,
22
- )
23
- end
24
-
25
- def source_generator
26
- Definition::Context::Generator.new(
27
- custom_method_parser,
28
- custom_method_source_decorator,
29
- custom_methods_repository,
30
- )
31
- end
32
-
33
- def merger
34
- Definition::Context::Merger.new(
35
- holidays_by_month_repository,
36
- regions_repository,
37
- custom_methods_repository,
38
- )
39
- end
40
-
41
- def custom_method_parser
42
- Definition::Parser::CustomMethod.new(
43
- custom_method_validator,
44
- )
45
- end
46
-
47
- def custom_method_proc_decorator
48
- Definition::Decorator::CustomMethodProc.new
49
- end
50
-
51
- def custom_method_source_decorator
52
- Definition::Decorator::CustomMethodSource.new
53
- end
54
-
55
- def region_validator
56
- Definition::Validator::Region.new(
57
- regions_repository
58
- )
59
- end
60
-
61
- def custom_method_validator
62
- Definition::Validator::CustomMethod.new
63
- end
64
-
65
- def holidays_by_month_repository
66
- @holidays_repo ||= Definition::Repository::HolidaysByMonth.new
67
- end
68
-
69
- def regions_repository
70
- @regions_repo ||= Definition::Repository::Regions.new
71
- end
72
-
73
- def cache_repository
74
- @cache_repo ||= Definition::Repository::Cache.new
75
- end
76
-
77
- def proc_result_cache_repository
78
- @proc_result_cache_repo ||= Definition::Repository::ProcResultCache.new
79
- end
80
-
81
- def custom_methods_repository
82
- @custom_methods_repository ||= Definition::Repository::CustomMethods.new
83
- end
84
- end
85
- end
86
- end
@@ -1,106 +0,0 @@
1
- module Holidays
2
- module Option
3
- module Context
4
- class ParseOptions
5
- def initialize(regions_repo, region_validator, definition_merger)
6
- @regions_repo = regions_repo
7
- @region_validator = region_validator
8
- @definition_merger = definition_merger
9
- end
10
-
11
- # Returns [(arr)regions, (bool)observed, (bool)informal]
12
- def call(*options)
13
- options.flatten!
14
-
15
- #TODO This is garbage. These two deletes MUST come before the
16
- # parse_regions call, otherwise it thinks that :observed and :informal
17
- # are regions to parse. We should be splitting these things out.
18
- observed = options.delete(:observed) ? true : false
19
- informal = options.delete(:informal) ? true : false
20
- regions = parse_regions!(options)
21
-
22
- return regions, observed, informal
23
- end
24
-
25
- private
26
-
27
- attr_reader :regions_repo, :region_validator, :definition_merger
28
-
29
- # Check regions against list of supported regions and return an array of
30
- # symbols.
31
- #
32
- # If a wildcard region is found (e.g. :ca_) it is expanded into all
33
- # of its available sub regions.
34
- def parse_regions!(regions)
35
- regions = [regions] unless regions.kind_of?(Array)
36
- return [:any] if regions.empty?
37
-
38
- regions = regions.collect { |r| r.to_sym }
39
-
40
- validate!(regions)
41
-
42
- # Found sub region wild-card
43
- regions.delete_if do |r|
44
- if r.to_s =~ /_$/
45
- load_containing_region(r.to_s)
46
- regions << regions_repo.search(r.to_s)
47
- true
48
- end
49
- end
50
-
51
- regions.flatten!
52
-
53
- load_definition_data("north_america") if regions.include?(:us) # special case for north_america/US cross-linking
54
-
55
- regions.each do |region|
56
- unless region == :any || regions_repo.exists?(region)
57
- begin
58
- load_definition_data(region.to_s)
59
- rescue NameError => e
60
- # This could be a sub region that does not have any holiday
61
- # definitions of its own; try to load the containing region instead.
62
- if region.to_s =~ /_/
63
- load_containing_region(region.to_s)
64
- else
65
- raise UnknownRegionError.new(e), "Could not load #{region.to_s}"
66
- end
67
- end
68
- end
69
- end
70
-
71
- regions
72
- end
73
-
74
- def validate!(regions)
75
- regions.each do |r|
76
- raise UnknownRegionError unless region_validator.valid?(r)
77
- end
78
- end
79
-
80
- # Derive the containing region from a sub region wild-card or a sub region
81
- # and load its definition. (Common code factored out from parse_regions)
82
- def load_containing_region(sub_reg)
83
- prefix = sub_reg.split('_').first
84
-
85
- return if regions_repo.exists?(prefix.to_sym)
86
-
87
- begin
88
- load_definition_data(prefix)
89
- rescue NameError => e
90
- raise UnknownRegionError.new(e), "Could not load region prefix: #{prefix.to_s}, original subregion: #{sub_reg.to_s}"
91
- end
92
- end
93
-
94
- def load_definition_data(region)
95
- target_region_module = Module.const_get("Holidays").const_get(region.upcase)
96
-
97
- definition_merger.call(
98
- target_region_module.defined_regions,
99
- target_region_module.holidays_by_month,
100
- target_region_module.custom_methods,
101
- )
102
- end
103
- end
104
- end
105
- end
106
- end
@@ -1,15 +0,0 @@
1
- require 'holidays/option/context/parse_options'
2
-
3
- module Holidays
4
- module OptionFactory
5
- class << self
6
- def parse_options
7
- Option::Context::ParseOptions.new(
8
- DefinitionFactory.regions_repository,
9
- DefinitionFactory.region_validator,
10
- DefinitionFactory.merger,
11
- )
12
- end
13
- end
14
- end
15
- end
@@ -1,45 +0,0 @@
1
- module Holidays
2
- module UseCase
3
- module Context
4
- class Between
5
- include ContextCommon
6
-
7
- def initialize(holidays_by_month_repo, day_of_month_calculator, custom_methods_repo, proc_result_cache_repo)
8
- @holidays_by_month_repo = holidays_by_month_repo
9
- @day_of_month_calculator = day_of_month_calculator
10
- @custom_methods_repo = custom_methods_repo
11
- @proc_result_cache_repo = proc_result_cache_repo
12
- end
13
-
14
- def call(start_date, end_date, dates_driver, regions, observed, informal)
15
- validate!(start_date, end_date, dates_driver, regions)
16
-
17
- holidays = []
18
- holidays = make_date_array(dates_driver, regions, observed, informal)
19
- holidays = holidays.select{|holiday|holiday[:date].between?(start_date, end_date)}
20
- holidays.sort{|a, b| a[:date] <=> b[:date] }
21
- end
22
-
23
- private
24
-
25
- attr_reader :holidays_by_month_repo,
26
- :day_of_month_calculator,
27
- :custom_methods_repo,
28
- :proc_result_cache_repo
29
-
30
- def validate!(start_date, end_date, dates_driver, regions)
31
- raise ArgumentError unless start_date
32
- raise ArgumentError unless end_date
33
-
34
- raise ArgumentError if dates_driver.nil? || dates_driver.empty?
35
-
36
- dates_driver.each do |year, months|
37
- raise ArgumentError if months.nil? || months.empty?
38
- end
39
-
40
- raise ArgumentError if regions.nil? || regions.empty?
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,123 +0,0 @@
1
- module Holidays
2
- module UseCase
3
- module Context
4
- module ContextCommon
5
- def make_date_array(dates_driver, regions, observed, informal)
6
- holidays = []
7
- dates_driver.each do |year, months|
8
- months.each do |month|
9
- next unless hbm = holidays_by_month_repo.find_by_month(month)
10
- hbm.each do |h|
11
- next unless in_region?(regions, h[:regions])
12
- next if h[:type] == :informal && !informal
13
-
14
- # range check feature.
15
- if h[:year_ranges]
16
- valid_range_year = false
17
- h[:year_ranges].each do |year_range|
18
- next unless year_range.is_a?(Hash) && year_range.length == 1
19
- next unless year_range.select{
20
- |operator,year|[:before,"before",:after,"after",:limited,"limited",:between,"between"].include?(operator)}.count > 0
21
- case year_range.keys.first
22
- when :before,"before"
23
- valid_range_year = true if year <= year_range[year_range.keys.first]
24
- when :after,"after"
25
- valid_range_year = true if year >= year_range[year_range.keys.first]
26
- when :limited,"limited"
27
- valid_range_year = true if year_range[year_range.keys.first].include?(year)
28
- when :between,"between"
29
- year_range[year_range.keys.first] = Range.new(*year_range[year_range.keys.first].split("..").map(&:to_i)) if year_range[year_range.keys.first].is_a?(String)
30
- valid_range_year = true if year_range[year_range.keys.first].cover?(year)
31
- end
32
- break if valid_range_year
33
- end
34
- next unless valid_range_year
35
- end
36
-
37
- #FIXME I don't like this entire if/else. If it's a function, do something, else do some
38
- # weird mday logic? Bollocks. I think this should be a refactor target.
39
- if h[:function]
40
- function_arguments = []
41
-
42
- #FIXME This is a refactor target. We should also allow 'date'. Right now these are the only
43
- # three things that we allow in. I think having a more testable, robust approach here is vital.
44
- if h[:function_arguments].include?(:year)
45
- function_arguments << year
46
- end
47
-
48
- if h[:function_arguments].include?(:month)
49
- function_arguments << month
50
- end
51
-
52
- if h[:function_arguments].include?(:day)
53
- function_arguments << h[:mday]
54
- end
55
-
56
- result = call_proc(h[:function], *function_arguments)
57
-
58
- #FIXME This is a dangerous assumption. We should raise an error or something
59
- # if these procs return something unexpected.
60
- #
61
- # Procs may return either Date or an integer representing mday
62
- if result.kind_of?(Date)
63
- if h[:function_modifier]
64
- result = result + h[:function_modifier] # NOTE: This could be a positive OR negative number.
65
- end
66
-
67
- month = result.month
68
- mday = result.mday
69
- else
70
- mday = result
71
- end
72
- else
73
- mday = h[:mday] || day_of_month_calculator.call(year, month, h[:week], h[:wday])
74
- end
75
-
76
- # Silently skip bad mdays
77
- begin
78
- date = Date.civil(year, month, mday)
79
- rescue; next; end
80
-
81
- #FIXME We should be checking the function arguments and passing in what is specified.
82
- # Right now all 'observed' functions require 'date' but that is by convention. Nothing
83
- # is requiring that. We should be more explicit.
84
- if observed && h[:observed]
85
- date = call_proc(h[:observed], date)
86
- end
87
-
88
- holidays << {:date => date, :name => h[:name], :regions => h[:regions]}
89
- end
90
- end
91
- end
92
- holidays
93
- end
94
-
95
- def call_proc(function_id, *arguments)
96
- function = custom_methods_repo.find(function_id)
97
- raise Holidays::FunctionNotFound.new("Unable to find function with id '#{function_id}'") if function.nil?
98
-
99
- proc_result_cache_repo.lookup(function, *arguments)
100
- end
101
-
102
- # Check sub regions.
103
- #
104
- # When request :any, all holidays should be returned.
105
- # When requesting :ca_bc, holidays in :ca or :ca_bc should be returned.
106
- # When requesting :ca, holidays in :ca but not its subregions should be returned.
107
- def in_region?(requested, available) # :nodoc:
108
- return true if requested.include?(:any)
109
-
110
- # When an underscore is encountered, derive the parent regions
111
- # symbol and include both in the requested array.
112
- requested = requested.collect do |r|
113
- r.to_s =~ /_/ ? [r, r.to_s.gsub(/_[\w]*$/, '').to_sym] : r
114
- end
115
-
116
- requested = requested.flatten.uniq
117
-
118
- available.any? { |avail| requested.include?(avail) }
119
- end
120
- end
121
- end
122
- end
123
- end
@@ -1,54 +0,0 @@
1
- module Holidays
2
- module UseCase
3
- module Context
4
- class NextHoliday
5
- include ContextCommon
6
-
7
- def initialize(holidays_by_month_repo, day_of_month_calculator, custom_methods_repo, proc_result_cache_repo)
8
- @holidays_by_month_repo = holidays_by_month_repo
9
- @day_of_month_calculator = day_of_month_calculator
10
- @custom_methods_repo = custom_methods_repo
11
- @proc_result_cache_repo = proc_result_cache_repo
12
- end
13
-
14
- def call(holidays_count, from_date, dates_driver, regions, observed, informal)
15
- validate!(holidays_count, from_date, dates_driver, regions)
16
- holidays = []
17
- ret_holidays = []
18
-
19
- ret_holidays = make_date_array(dates_driver, regions, observed, informal)
20
- ret_holidays.each do |holiday|
21
- if holiday[:date] >= from_date
22
- holidays << holiday
23
- holidays_count -= 1
24
- break if holidays_count == 0
25
- end
26
- end
27
-
28
- holidays.sort{|a, b| a[:date] <=> b[:date] }
29
- end
30
-
31
- private
32
-
33
- attr_reader :holidays_by_month_repo,
34
- :day_of_month_calculator,
35
- :custom_methods_repo,
36
- :proc_result_cache_repo
37
-
38
- def validate!(holidays_count, from_date, dates_driver, regions)
39
- raise ArgumentError unless holidays_count
40
- raise ArgumentError if holidays_count <= 0
41
- raise ArgumentError unless from_date
42
-
43
- raise ArgumentError if dates_driver.nil? || dates_driver.empty?
44
-
45
- dates_driver.each do |year, months|
46
- raise ArgumentError if months.nil? || months.empty?
47
- end
48
-
49
- raise ArgumentError if regions.nil? || regions.empty?
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,31 +0,0 @@
1
- require 'holidays/use_case/context/context_common'
2
- require 'holidays/use_case/context/between'
3
- require 'holidays/use_case/context/next_holiday'
4
- require 'holidays/use_case/context/dates_driver_builder'
5
-
6
- module Holidays
7
- class UseCaseFactory
8
- class << self
9
- def between
10
- UseCase::Context::Between.new(
11
- DefinitionFactory.holidays_by_month_repository,
12
- DateCalculatorFactory.day_of_month_calculator,
13
- DefinitionFactory.custom_methods_repository,
14
- DefinitionFactory.proc_result_cache_repository,
15
- )
16
- end
17
- def next_holiday
18
- UseCase::Context::NextHoliday.new(
19
- DefinitionFactory.holidays_by_month_repository,
20
- DateCalculatorFactory.day_of_month_calculator,
21
- DefinitionFactory.custom_methods_repository,
22
- DefinitionFactory.proc_result_cache_repository,
23
- )
24
- end
25
-
26
- def dates_driver_builder
27
- UseCase::Context::DatesDriverBuilder.new
28
- end
29
- end
30
- end
31
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
3
-
4
- # This file is generated by the Ruby Holiday gem.
5
- #
6
- # Definitions loaded: definitions/ecb_target.yaml
7
- class Ecb_targetDefinitionTests < Test::Unit::TestCase # :nodoc:
8
-
9
- def test_ecb_target
10
- {Date.civil(2013,1,1) => 'New Year\'s Day',
11
- Date.civil(2013,5,1) => 'Labour Day',
12
- Date.civil(2013,3,29) => 'Good Friday',
13
- Date.civil(2013,4,1) => 'Easter Monday',
14
- Date.civil(2013,12,25) => 'Christmas Day',
15
- Date.civil(2013,12,26) => 'Christmas Holiday'}.each do |date, name|
16
- assert_equal name, (Holidays.on(date, :ecb_target)[0] || {})[:name]
17
- end
18
-
19
- assert_equal 'Good Friday', Holidays.on(Date.civil(2013,3,29), :ecb_target)[0][:name]
20
- assert_equal 'Easter Monday', Holidays.on(Date.civil(2013,4,1), :ecb_target)[0][:name]
21
-
22
- end
23
- end