holidays 9.2.0 → 10.0.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.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +38 -2
  4. data/lib/generated_definitions/au.rb +16 -42
  5. data/lib/generated_definitions/europe.rb +2 -10
  6. data/lib/generated_definitions/lu.rb +1 -1
  7. data/lib/generated_definitions/nz.rb +9 -1
  8. data/lib/generated_definitions/pl.rb +3 -11
  9. data/lib/holidays/definition/context/function_processor.rb +4 -5
  10. data/lib/holidays/definition/context/generator.rb +3 -1
  11. data/lib/holidays/version.rb +1 -1
  12. metadata +3 -313
  13. data/.github/workflows/changelog-check.yml +0 -47
  14. data/.github/workflows/release.yml +0 -46
  15. data/.github/workflows/ruby.yml +0 -26
  16. data/.gitmodules +0 -3
  17. data/CODE_OF_CONDUCT.md +0 -74
  18. data/Gemfile +0 -8
  19. data/Makefile +0 -60
  20. data/Rakefile +0 -137
  21. data/bin/console +0 -7
  22. data/bin/setup +0 -6
  23. data/doc/CONTRIBUTING.md +0 -72
  24. data/doc/MAINTAINERS.md +0 -79
  25. data/doc/REFERENCES +0 -19
  26. data/holidays.gemspec +0 -31
  27. data/test/coverage_report.rb +0 -24
  28. data/test/data/test_custom_year_range_holiday_defs.yaml +0 -31
  29. data/test/data/test_date_transform_conflict_region_1.yaml +0 -14
  30. data/test/data/test_date_transform_conflict_region_2.yaml +0 -14
  31. data/test/data/test_invalid_region.rb +0 -15
  32. data/test/data/test_region.rb +0 -15
  33. data/test/data/test_single_custom_holiday_defs.yaml +0 -12
  34. data/test/data/test_single_custom_holiday_with_custom_procs.yaml +0 -28
  35. data/test/defs/test_defs_ar.rb +0 -69
  36. data/test/defs/test_defs_at.rb +0 -31
  37. data/test/defs/test_defs_au.rb +0 -233
  38. data/test/defs/test_defs_be_fr.rb +0 -45
  39. data/test/defs/test_defs_be_nl.rb +0 -45
  40. data/test/defs/test_defs_bg.rb +0 -41
  41. data/test/defs/test_defs_br.rb +0 -49
  42. data/test/defs/test_defs_ca.rb +0 -289
  43. data/test/defs/test_defs_ch.rb +0 -51
  44. data/test/defs/test_defs_cl.rb +0 -69
  45. data/test/defs/test_defs_co.rb +0 -113
  46. data/test/defs/test_defs_cr.rb +0 -29
  47. data/test/defs/test_defs_cy.rb +0 -41
  48. data/test/defs/test_defs_cz.rb +0 -37
  49. data/test/defs/test_defs_de.rb +0 -91
  50. data/test/defs/test_defs_dk.rb +0 -47
  51. data/test/defs/test_defs_ecbtarget.rb +0 -27
  52. data/test/defs/test_defs_ee.rb +0 -41
  53. data/test/defs/test_defs_es.rb +0 -137
  54. data/test/defs/test_defs_europe.rb +0 -1530
  55. data/test/defs/test_defs_fed_ex.rb +0 -24
  56. data/test/defs/test_defs_federalreserve.rb +0 -119
  57. data/test/defs/test_defs_federalreservebanks.rb +0 -251
  58. data/test/defs/test_defs_fedex.rb +0 -31
  59. data/test/defs/test_defs_fi.rb +0 -59
  60. data/test/defs/test_defs_fr.rb +0 -43
  61. data/test/defs/test_defs_gb.rb +0 -163
  62. data/test/defs/test_defs_ge.rb +0 -53
  63. data/test/defs/test_defs_gr.rb +0 -41
  64. data/test/defs/test_defs_hk.rb +0 -93
  65. data/test/defs/test_defs_hr.rb +0 -45
  66. data/test/defs/test_defs_hu.rb +0 -47
  67. data/test/defs/test_defs_ie.rb +0 -53
  68. data/test/defs/test_defs_il.rb +0 -35
  69. data/test/defs/test_defs_in.rb +0 -94
  70. data/test/defs/test_defs_is.rb +0 -51
  71. data/test/defs/test_defs_it.rb +0 -57
  72. data/test/defs/test_defs_jp.rb +0 -159
  73. data/test/defs/test_defs_ke.rb +0 -31
  74. data/test/defs/test_defs_kr.rb +0 -37
  75. data/test/defs/test_defs_kz.rb +0 -39
  76. data/test/defs/test_defs_li.rb +0 -35
  77. data/test/defs/test_defs_lt.rb +0 -65
  78. data/test/defs/test_defs_lu.rb +0 -35
  79. data/test/defs/test_defs_lv.rb +0 -98
  80. data/test/defs/test_defs_ma.rb +0 -29
  81. data/test/defs/test_defs_mc.rb +0 -43
  82. data/test/defs/test_defs_mt_en.rb +0 -41
  83. data/test/defs/test_defs_mt_mt.rb +0 -41
  84. data/test/defs/test_defs_mx.rb +0 -49
  85. data/test/defs/test_defs_my.rb +0 -23
  86. data/test/defs/test_defs_nerc.rb +0 -29
  87. data/test/defs/test_defs_ng.rb +0 -29
  88. data/test/defs/test_defs_nl.rb +0 -33
  89. data/test/defs/test_defs_no.rb +0 -43
  90. data/test/defs/test_defs_northamerica.rb +0 -679
  91. data/test/defs/test_defs_nyse.rb +0 -46
  92. data/test/defs/test_defs_nz.rb +0 -67
  93. data/test/defs/test_defs_pe.rb +0 -47
  94. data/test/defs/test_defs_ph.rb +0 -29
  95. data/test/defs/test_defs_pl.rb +0 -229
  96. data/test/defs/test_defs_pt.rb +0 -47
  97. data/test/defs/test_defs_ro.rb +0 -69
  98. data/test/defs/test_defs_rs_cyrl.rb +0 -46
  99. data/test/defs/test_defs_rs_la.rb +0 -46
  100. data/test/defs/test_defs_ru.rb +0 -34
  101. data/test/defs/test_defs_scandinavia.rb +0 -215
  102. data/test/defs/test_defs_se.rb +0 -59
  103. data/test/defs/test_defs_sg.rb +0 -25
  104. data/test/defs/test_defs_si.rb +0 -105
  105. data/test/defs/test_defs_sk.rb +0 -37
  106. data/test/defs/test_defs_southamerica.rb +0 -327
  107. data/test/defs/test_defs_th.rb +0 -33
  108. data/test/defs/test_defs_tn.rb +0 -27
  109. data/test/defs/test_defs_tr.rb +0 -60
  110. data/test/defs/test_defs_tsx.rb +0 -70
  111. data/test/defs/test_defs_ua.rb +0 -41
  112. data/test/defs/test_defs_unitednations.rb +0 -11
  113. data/test/defs/test_defs_ups.rb +0 -31
  114. data/test/defs/test_defs_us.rb +0 -399
  115. data/test/defs/test_defs_ve.rb +0 -35
  116. data/test/defs/test_defs_vi.rb +0 -22
  117. data/test/defs/test_defs_za.rb +0 -35
  118. data/test/e2e/README.md +0 -52
  119. data/test/e2e/data/test_multiple_regions_with_conflicts_region_1.yaml +0 -38
  120. data/test/e2e/data/test_multiple_regions_with_conflicts_region_2.yaml +0 -38
  121. data/test/e2e/data/test_multiple_regions_with_conflicts_region_3.yaml +0 -38
  122. data/test/e2e/test_all_regions.rb +0 -49
  123. data/test/e2e/test_any_holidays_during_work_week.rb +0 -90
  124. data/test/e2e/test_holidays.rb +0 -244
  125. data/test/e2e/test_holidays_between.rb +0 -87
  126. data/test/e2e/test_multiple_regions.rb +0 -71
  127. data/test/e2e/test_multiple_regions_with_conflict.rb +0 -228
  128. data/test/e2e/test_nonstandard_regions.rb +0 -25
  129. data/test/holidays/core_extensions/test_date.rb +0 -122
  130. data/test/holidays/core_extensions/test_date_time.rb +0 -60
  131. data/test/holidays/date_calculator/test_day_of_month.rb +0 -27
  132. data/test/holidays/date_calculator/test_easter_gregorian.rb +0 -30
  133. data/test/holidays/date_calculator/test_easter_julian.rb +0 -36
  134. data/test/holidays/date_calculator/test_lunar_date.rb +0 -89
  135. data/test/holidays/date_calculator/test_weekend_modifier.rb +0 -54
  136. data/test/holidays/definition/context/test_function_processor.rb +0 -199
  137. data/test/holidays/definition/context/test_generator.rb +0 -226
  138. data/test/holidays/definition/context/test_load.rb +0 -37
  139. data/test/holidays/definition/context/test_merger.rb +0 -25
  140. data/test/holidays/definition/decorator/test_custom_method_proc.rb +0 -113
  141. data/test/holidays/definition/decorator/test_custom_method_source.rb +0 -96
  142. data/test/holidays/definition/decorator/test_test.rb +0 -123
  143. data/test/holidays/definition/generator/test_module.rb +0 -268
  144. data/test/holidays/definition/generator/test_regions.rb +0 -97
  145. data/test/holidays/definition/generator/test_test.rb +0 -113
  146. data/test/holidays/definition/parser/test_custom_method.rb +0 -79
  147. data/test/holidays/definition/parser/test_test.rb +0 -142
  148. data/test/holidays/definition/repository/test_cache.rb +0 -123
  149. data/test/holidays/definition/repository/test_custom_methods.rb +0 -43
  150. data/test/holidays/definition/repository/test_holidays_by_month.rb +0 -275
  151. data/test/holidays/definition/repository/test_proc_result_cache.rb +0 -91
  152. data/test/holidays/definition/repository/test_regions.rb +0 -104
  153. data/test/holidays/definition/validator/test_custom_method.rb +0 -94
  154. data/test/holidays/definition/validator/test_region.rb +0 -54
  155. data/test/holidays/definition/validator/test_test.rb +0 -60
  156. data/test/holidays/finder/context/test_between.rb +0 -172
  157. data/test/holidays/finder/context/test_dates_driver_builder.rb +0 -91
  158. data/test/holidays/finder/context/test_next_holiday.rb +0 -156
  159. data/test/holidays/finder/context/test_parse_options.rb +0 -141
  160. data/test/holidays/finder/context/test_search.rb +0 -290
  161. data/test/holidays/finder/context/test_year_holiday.rb +0 -202
  162. data/test/holidays/finder/rules/test_in_region.rb +0 -42
  163. data/test/holidays/finder/rules/test_year_range.rb +0 -166
  164. data/test/integration/README.md +0 -48
  165. data/test/integration/data/test_custom_govt_holiday_defs.yaml +0 -5
  166. data/test/integration/data/test_custom_informal_holidays_defs.yaml +0 -11
  167. data/test/integration/data/test_multiple_custom_holiday_defs.yaml +0 -12
  168. data/test/integration/test_custom_holidays.rb +0 -41
  169. data/test/integration/test_custom_informal_holidays.rb +0 -15
  170. data/test/integration/test_custom_year_range_holidays.rb +0 -35
  171. data/test/smoke/README.md +0 -31
  172. data/test/smoke/test_available_regions.rb +0 -18
  173. data/test/smoke/test_smoke.rb +0 -74
  174. data/test/test_helper.rb +0 -37
@@ -1,38 +0,0 @@
1
- months:
2
- 0:
3
- - name: With Function Modifier
4
- regions: [multiple_with_conflict_3]
5
- function: easter(year)
6
- function_modifier: 70
7
- - name: With Function Only Different Function Name
8
- regions: [multiple_with_conflict_3]
9
- function: conflict_custom_method_3(year)
10
- - name: With Function Only Same Function Name
11
- regions: [multiple_with_conflict_3]
12
- function: conflict_custom_method_identical_name_between_regions(year)
13
- - name: With Function Only Same Function Name - Region 3
14
- regions: [multiple_with_conflict_3]
15
- function: conflict_custom_method_identical_name_between_regions_but_different_holiday_names(year)
16
- 1:
17
- - name: New Year's Day
18
- regions: [multiple_with_conflict_3]
19
- mday: 1
20
- observed: to_monday_if_weekend(date)
21
- 10:
22
- - name: Testing Conflict Month 10
23
- regions: [multiple_with_conflict_3]
24
- mday: 9
25
-
26
- methods:
27
- conflict_custom_method_3:
28
- arguments: year
29
- ruby: |
30
- Date.civil(year, 4, 1)
31
- conflict_custom_method_identical_name_between_regions:
32
- arguments: year
33
- ruby: |
34
- Date.civil(year, 3, 1)
35
- conflict_custom_method_identical_name_between_regions_but_different_holiday_names:
36
- arguments: year
37
- ruby: |
38
- Date.civil(year, 3, 15)
@@ -1,49 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
-
3
- class AllRegionsTests < Test::Unit::TestCase
4
- def setup
5
- Holidays::LoadAllDefinitions.call
6
- end
7
-
8
- def test_definition_dir
9
- assert File.directory?(Holidays::FULL_DEFINITIONS_PATH)
10
- end
11
-
12
- def test_show_available_regions
13
- regions = Holidays.available_regions
14
-
15
- assert_equal regions.size, Holidays::REGIONS.size
16
- assert_equal regions, Holidays::REGIONS
17
- end
18
-
19
- def test_load_subregion
20
- holidays = Holidays.on(Date.civil(2014, 1, 1), :de_bb)
21
- assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
22
-
23
- holidays = Holidays.on(Date.civil(2020, 1, 1), :de_bb)
24
- assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
25
-
26
- holidays = Holidays.on(Date.civil(2027, 1, 1), :de_bb)
27
- assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
28
- end
29
-
30
- def test_unknown_region_raises_exception
31
- assert_raise Holidays::InvalidRegion do
32
- Holidays.on(Date.civil(2014, 1, 1), :something_we_do_not_recognize)
33
- end
34
-
35
- assert_raise Holidays::InvalidRegion do
36
- Holidays.on(Date.civil(2020, 1, 1), :something_we_do_not_recognize)
37
- end
38
-
39
- assert_raise Holidays::InvalidRegion do
40
- Holidays.on(Date.civil(2030, 1, 1), :something_we_do_not_recognize)
41
- end
42
- end
43
-
44
- def test_malicious_load_attempt_raises_exception
45
- assert_raise Holidays::InvalidRegion do
46
- Holidays.between(Date.civil(2014, 1, 1), Date.civil(2016, 1, 1), '../../../../../../../../../../../../tmp/profile_pic.jpg')
47
- end
48
- end
49
- end
@@ -1,90 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
-
3
- class AnyHolidaysDuringWorkWeekTests < Test::Unit::TestCase
4
- def subject
5
- Holidays.method(:any_holidays_during_work_week?)
6
- end
7
-
8
- def test_returns_true_when_single_holiday_exists_during_week
9
- assert subject.call(Date.new(2018, 1, 1), :us)
10
- end
11
-
12
- def test_returns_true_when_multiple_holidays_exist_during_week
13
- assert subject.call(Date.new(2018, 12, 26), :gb)
14
- end
15
-
16
- def test_returns_true_if_informal_flag_set_and_informal_holiday_exists_during_week
17
- assert subject.call(Date.new(2018, 10, 31), :us, :informal)
18
- end
19
-
20
- def test_returns_true_when_no_region_specified_and_single_holiday_exists_during_week
21
- assert subject.call(Date.new(2018, 1, 1))
22
- end
23
-
24
- def test_returns_true_if_both_informal_and_observed_flags_set_and_informal_holiday_observed_during_week
25
- assert subject.call(Date.new(2008, 11, 30), :gb_sct, :informal, :observed)
26
- end
27
-
28
- def test_returns_true_when_observed_flag_set_and_holiday_is_observed_during_week
29
- assert subject.call(Date.new(2012,9,5), :us, :observed)
30
- end
31
-
32
- def test_returns_true_when_observed_flag_set_and_holiday_is_observed_on_monday
33
- assert subject.call(Date.new(2018,11,12), :us, :observed)
34
- end
35
-
36
- def test_returns_true_with_multiple_regions_and_holiday_occurs_during_week
37
- assert subject.call(Date.new(2018,1,1), [:us, :gb])
38
- end
39
-
40
- def test_returns_true_when_observed_flag_set_and_holiday_on_saturday_but_observed_on_friday
41
- assert subject.call(Date.new(2018,7,3), [:us], :observed)
42
- end
43
-
44
- def test_returns_false_when_no_holiday_exists_during_week
45
- assert_equal false, subject.call(Date.new(2018,7,30), :us)
46
- end
47
-
48
- def test_returns_false_when_holiday_on_sunday
49
- assert_equal false, subject.call(Date.new(2018,11,11), :us)
50
- end
51
-
52
- def test_returns_false_when_holiday_on_saturday
53
- assert_equal false, subject.call(Date.new(2017,11,11), :us)
54
- end
55
-
56
- def test_returns_false_when_observed_flag_not_set_and_holiday_occurs_on_sunday_but_observed_on_monday
57
- assert_equal false, subject.call(Date.new(2017,1,1), :us)
58
- end
59
-
60
- def test_returns_false_if_informal_and_observed_flags_both_set_and_no_holiday_exists_during_week
61
- assert_equal false, subject.call(Date.new(2018,7,30), :us, :informal, :observed)
62
- end
63
-
64
- def test_returns_false_when_informal_flag_set_and_informal_holiday_occurs_on_weekend
65
- assert_equal false, subject.call(Date.new(2018,4,14), :us, :informal)
66
- end
67
-
68
- def test_returns_false_when_informal_flag_set_but_observed_is_not_and_informal_holiday_is_observed_on_monday
69
- assert_equal false, subject.call(Date.new(2008, 11, 30), :gb_sct, :informal)
70
- end
71
-
72
- def test_verify_count_of_weeks_without_any_holidays_for_2012
73
- weeks_in_2012 = Date.commercial(2013, -1).cweek
74
- holidays_in_2012 = weeks_in_2012.times.count { |week| subject.call(Date.commercial(2012,week+1), :us) == false }
75
- assert_equal 45, holidays_in_2012
76
- end
77
-
78
- def test_returns_true_for_new_years_in_any_region
79
- assert subject.call(Date.civil(2016, 1, 1))
80
- end
81
-
82
- # These are in response to https://github.com/holidays/holidays/issues/264, just to be completely sure it's fixed.
83
- def returns_true_for_various_holidays_in_poland
84
- assert subject.call(Date.civil(2018, 1, 1), :pl)
85
- assert subject.call(Date.civil(2018, 1, 2), :pl)
86
- assert subject.call(Date.civil(2018, 5, 2), :pl)
87
- assert subject.call(Date.civil(2018, 5, 3), :pl)
88
- assert subject.call(Date.today, Date.today + 365*2, :pl, :observed)
89
- end
90
- end
@@ -1,244 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
3
-
4
- class HolidaysTests < Test::Unit::TestCase
5
- def setup
6
- @date = Date.civil(2008,1,1)
7
- end
8
-
9
- def test_on
10
- h = Holidays.on(Date.civil(2008,9,1), :ca)
11
- assert_equal 'Labour Day', h[0][:name]
12
-
13
- holidays = Holidays.on(Date.civil(2008,7,4), :ca)
14
- assert_equal 0, holidays.length
15
- end
16
-
17
- def test_requires_valid_regions
18
- assert_raises Holidays::InvalidRegion do
19
- Holidays.on(Date.civil(2008,1,1), :xx)
20
- end
21
-
22
- assert_raises Holidays::InvalidRegion do
23
- Holidays.on(Date.civil(2008,1,1), [:ca,:xx])
24
- end
25
-
26
- assert_raises Holidays::InvalidRegion do
27
- Holidays.between(Date.civil(2008,1,1), Date.civil(2008,12,31), [:ca,:xx])
28
- end
29
- end
30
-
31
- def test_requires_valid_regions_holiday_next
32
- assert_raises Holidays::InvalidRegion do
33
- Holidays.next_holidays(1, [:xx], Date.civil(2008,1,1))
34
- end
35
-
36
- assert_raises Holidays::InvalidRegion do
37
- Holidays.next_holidays(1, [:ca,:xx], Date.civil(2008,1,1))
38
- Holidays.on(Date.civil(2008,1,1), [:ca,:xx])
39
- end
40
-
41
- assert_raises Holidays::InvalidRegion do
42
- Holidays.next_holidays(1, [:ca,:xx])
43
- end
44
- end
45
-
46
- def test_region_params
47
- holidays = Holidays.on(@date, :ca)
48
- assert_equal 1, holidays.length
49
-
50
- holidays = Holidays.on(@date, [:ca_bc,:ca])
51
- assert_equal 1, holidays.length
52
- end
53
-
54
- def test_observed_dates
55
- # Should fall on Tuesday the 1st
56
- assert_equal 1, Holidays.on(Date.civil(2008,7,1), :ca, :observed).length
57
-
58
- # Should fall on Monday the 2nd
59
- assert_equal 1, Holidays.on(Date.civil(2007,7,2), :ca, :observed).length
60
- end
61
-
62
- def test_any_region
63
- # Should return nothing(Victoria Day is not celebrated :ca wide anymore)
64
- holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
65
- assert_equal 0, holidays.length
66
-
67
- # Should return Victoria Day and National Patriotes Day.
68
- #
69
- # Should be 2 in the CA region but other regional files are loaded during the
70
- # unit tests add to the :any count.
71
- holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), [:any])
72
- assert holidays.length >= 2
73
-
74
- # Test blank region
75
- holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31))
76
- assert holidays.length >= 3
77
- end
78
-
79
- def test_any_region_holiday_next
80
- # Should return Victoria Day.
81
- holidays = Holidays.next_holidays(1, [:ca], Date.civil(2008,5,1))
82
- assert_equal 1, holidays.length
83
- assert_equal ['2008-07-01','Canada Day'] , [holidays.first[:date].to_s, holidays.first[:name].to_s]
84
-
85
- # Should return 2 holidays.
86
- holidays = Holidays.next_holidays(2, [:ca], Date.civil(2008,5,1))
87
- assert_equal 2, holidays.length
88
-
89
- # Should return 1 holiday in July
90
- holidays = Holidays.next_holidays(1, [:jp], Date.civil(2016, 5, 22))
91
- assert_equal ['2016-07-18','海の日'] , [holidays.first[:date].to_s, holidays.first[:name].to_s]
92
-
93
- # Must Region.If there is not region, raise ArgumentError.
94
- assert_raises ArgumentError do
95
- Holidays.next_holidays(2, '', Date.civil(2008,5,1))
96
- end
97
- # Options should be present.If they are empty, raise ArgumentError.
98
- assert_raises ArgumentError do
99
- Holidays.next_holidays(2, [], Date.civil(2008,5,1))
100
- end
101
- # Options should be Array.If they are not Array, raise ArgumentError.
102
- assert_raises ArgumentError do
103
- Holidays.next_holidays(2, :ca, Date.civil(2008,5,1))
104
- end
105
- end
106
-
107
- def test_year_holidays
108
- # Should return 7 holidays from February 23 to December 31
109
- holidays = Holidays.year_holidays([:ca_on], Date.civil(2016, 2, 23))
110
- assert_equal 7, holidays.length
111
-
112
- # Must have options (Regions)
113
- assert_raises ArgumentError do
114
- Holidays.year_holidays([], Date.civil(2016, 2, 23))
115
- end
116
-
117
- # Options must be in the form of an array.
118
- assert_raises ArgumentError do
119
- Holidays.year_holidays(:ca_on, Date.civil(2016, 2, 23))
120
- end
121
- end
122
-
123
- def test_year_holidays_with_specified_year
124
- # Should return all 11 holidays for 2016 in Ontario, Canada
125
- holidays = Holidays.year_holidays([:ca_on], Date.civil(2016, 1, 1))
126
- assert_equal 9, holidays.length
127
-
128
- # Should return all 5 holidays for 2016 in Australia
129
- holidays = Holidays.year_holidays([:au], Date.civil(2016, 1, 1))
130
- assert_equal 5, holidays.length
131
- end
132
-
133
- def test_year_holidays_empty
134
- # if remain holidays is nothing , method will return empty.
135
- holidays = Holidays.year_holidays([:ca_on], Date.civil(2016, 12, 27))
136
- assert_empty holidays
137
- end
138
-
139
- def test_year_holidays_random_years
140
- # Should be 1 less holiday, as Family day didn't exist in Ontario in 1990
141
- holidays = Holidays.year_holidays([:ca_on], Date.civil(1990, 1, 1))
142
- assert_equal 8, holidays.length
143
-
144
- # Family day still didn't exist in 2000
145
- holidays = Holidays.year_holidays([:ca_on], Date.civil(2000, 1, 1))
146
- assert_equal 8, holidays.length
147
-
148
- holidays = Holidays.year_holidays([:ca_on], Date.civil(2020, 1, 1))
149
- assert_equal 11, holidays.length
150
-
151
- holidays = Holidays.year_holidays([:ca_on], Date.civil(2050, 1, 1))
152
- assert_equal 9, holidays.length
153
-
154
- holidays = Holidays.year_holidays([:jp], Date.civil(2070, 1, 1))
155
- assert_equal 19, holidays.length
156
- end
157
-
158
- def test_sub_regions
159
- # Should return nothing (Victoria Day is no longer :ca wide)
160
- holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
161
- assert_equal 0, holidays.length
162
-
163
- ## Should return National Patriotes Day.
164
- holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca_qc)
165
- assert_equal 1, holidays.length
166
-
167
- # Should return Victoria Day and National Patriotes Day.
168
- holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca_)
169
- assert_equal 3, holidays.length
170
- end
171
-
172
- def test_sub_regions_holiday_next
173
- # Should return Victoria Day.
174
- holidays = Holidays.next_holidays(2, [:ca_bc], Date.civil(2008,5,1))
175
- assert_equal 2, holidays.length
176
- assert_equal ['2008-05-19','Victoria Day'] , [holidays.first[:date].to_s, holidays.first[:name].to_s]
177
-
178
- # Should return Victoria Da and National Patriotes Day.
179
- holidays = Holidays.next_holidays(2, [:ca_qc], Date.civil(2008,5,1))
180
- assert_equal 2, holidays.length
181
- assert_equal ['2008-06-24','Fête Nationale'] , [holidays.last[:date].to_s, holidays.last[:name].to_s]
182
-
183
- # Should return Victoria Day and National Patriotes Day.
184
- holidays = Holidays.next_holidays(2, [:ca_], Date.civil(2008,5,1))
185
- assert_equal 2, holidays.length
186
-
187
- # Aparently something in jruby doesn't sort the same way as other rubies so....we'll just do it ourselves so
188
- # we don't flap.
189
- sorted_holidays = holidays.sort_by { |h| h[:name] }
190
- assert_equal ['2008-05-19','National Patriotes Day'] , [sorted_holidays.first[:date].to_s, sorted_holidays.first[:name].to_s]
191
- assert_equal ['2008-05-19','Victoria Day'] , [sorted_holidays.last[:date].to_s, sorted_holidays.last[:name].to_s]
192
- end
193
-
194
- def test_easter_lambda
195
- [Date.civil(1800,4,11), Date.civil(1899,3,31), Date.civil(1900,4,13),
196
- Date.civil(2008,3,21), Date.civil(2035,3,23)].each do |date|
197
- assert_equal 'Good Friday', Holidays.on(date, :ca)[0][:name]
198
- end
199
-
200
- [Date.civil(1800,4,14), Date.civil(1899,4,3), Date.civil(1900,4,16),
201
- Date.civil(2008,3,24), Date.civil(2035,3,26)].each do |date|
202
- assert_equal 'Easter Monday', Holidays.on(date, :ca_qc, :informal)[0][:name]
203
- end
204
- end
205
-
206
- def test_sorting
207
- (1..10).each{|year|
208
- (1..12).each{|month|
209
- holidays = Holidays.between(Date.civil(year, month, 1), Date.civil(year, month, 28), :gb_)
210
- holidays.each_with_index{|holiday, index|
211
- assert holiday[:date] >= holidays[index - 1][:date] if index > 0
212
- }
213
- }
214
- }
215
- end
216
-
217
- def test_caching
218
- good_friday = Date.civil(2008, 3, 21)
219
- easter_monday = Date.civil(2008, 3, 24)
220
- cache_end_date = Date.civil(2008, 3, 25)
221
-
222
- Holidays.cache_between(good_friday, cache_end_date, :ca, :informal)
223
-
224
- # Test that correct results are returned outside the
225
- # cache range, and with no caching
226
- assert_equal 1, Holidays.on(Date.civil(2035, 1, 1), :ca, :informal).length
227
- assert_equal 1, Holidays.on(Date.civil(2035, 1, 1), :us).length
228
-
229
- # Make sure cache is hit for all successive calls
230
- Holidays::Factory::Finder.expects(:between).never
231
-
232
- # Test that cache has been set and it returns the same as before
233
- assert_equal 1, Holidays.on(good_friday, :ca, :informal).length
234
- assert_equal 1, Holidays.on(easter_monday, :ca, :informal).length
235
- assert_equal 1, easter_monday.holidays(:ca, :informal).length
236
- assert_equal true, easter_monday.holiday?(:ca, :informal)
237
- end
238
-
239
- def test_load_all
240
- assert_nothing_raised do
241
- Holidays.load_all
242
- end
243
- end
244
- end
@@ -1,87 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
-
3
- require "#{Holidays::DEFINITIONS_PATH}/ca"
4
-
5
- # Re-include CA defs via holidays/north_america to ensure that individual
6
- # defs aren't duplicated.
7
- #
8
- # NOTE: this test is a mixture of integration and unit tests. It's messy and bad.
9
- # I am not fixing it here because I am trying to clean up the 'between' use case
10
- # and don't want to bite off more than I can chew.
11
- require "#{Holidays::DEFINITIONS_PATH}/northamerica"
12
-
13
- class HolidaysBetweenTests < Test::Unit::TestCase
14
- def setup
15
- @date = Date.civil(2008,1,1)
16
- @subject = Holidays.method(:between)
17
- end
18
-
19
- def teardown
20
- Holidays::Factory::Definition.cache_repository.reset!
21
- end
22
-
23
- def test_between
24
- holidays = @subject.call(Date.civil(2008,7,1), Date.civil(2008,7,1), :ca)
25
- assert_equal 1, holidays.length
26
-
27
- holidays = @subject.call(Date.civil(2008,7,1), Date.civil(2008,7,31), :ca)
28
- assert_equal 1, holidays.length
29
-
30
- holidays = @subject.call(Date.civil(2008,7,2), Date.civil(2008,7,31), :ca)
31
- assert_equal 0, holidays.length
32
- end
33
-
34
- def test_between_raises_error_if_missing_start_or_end_date
35
- assert_raise ArgumentError do
36
- @subject.call(nil, Date.civil(2015, 1, 1), :us)
37
- end
38
-
39
- assert_raise ArgumentError do
40
- @subject.call(Date.civil(2015, 1, 1), nil, :us)
41
- end
42
- end
43
-
44
- def test_between_raises_error_if_end_date_is_before_start_date
45
- assert_raise ArgumentError do
46
- @subject.call(Date.civil(2019, 2, 1), Date.civil(2019, 1, 1), :us)
47
- end
48
-
49
- assert_raise ArgumentError do
50
- @subject.call(Date.civil(2008,7,2), Date.civil(2000,7,2), :ca)
51
- end
52
- end
53
-
54
- def test_cached_holidays_are_returned_if_present
55
- start_date = Date.civil(2015, 1, 1)
56
- end_date = Date.civil(2015, 1, 31)
57
- options = [:us, :informal]
58
-
59
- Holidays::Factory::Definition.cache_repository.expects(:find).with(start_date, end_date, options).returns({cached: 'data'})
60
-
61
- assert_equal({cached: 'data'}, @subject.call(start_date, end_date, *options))
62
- end
63
-
64
- def test_options_are_parsed
65
- start_date = Date.civil(2015, 1, 1)
66
- end_date = Date.civil(2015, 1, 31)
67
- options = [:us]
68
-
69
- between_mock = mock()
70
- Holidays::Factory::Finder.stubs(:between).returns(between_mock)
71
- between_mock.expects(:call).with(start_date, end_date, [:us])
72
-
73
- @subject.call(start_date, end_date, *options)
74
- end
75
-
76
- def test_dates_driver_builder_is_called
77
- start_date = Date.civil(2015, 1, 1)
78
- end_date = Date.civil(2015, 1, 31)
79
- options = [:us]
80
-
81
- between_mock = mock()
82
- Holidays::Factory::Finder.stubs(:between).returns(between_mock)
83
- between_mock.expects(:call).with(start_date, end_date, [:us])
84
-
85
- @subject.call(start_date, end_date, *options)
86
- end
87
- end
@@ -1,71 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
- require "#{Holidays::DEFINITIONS_PATH}/gb"
3
- require "#{Holidays::DEFINITIONS_PATH}/ie"
4
-
5
- class MultipleRegionsTests < Test::Unit::TestCase
6
- # Simulate load of new environment where the repositories begin empty
7
- def reset_cache
8
- Holidays::Factory::Definition.instance_variable_set(:@regions_repo, nil)
9
- Holidays::Factory::Definition.instance_variable_set(:@holidays_repo, nil)
10
- end
11
-
12
- def test_defining_holidays
13
- h = Holidays.on(Date.new(2008, 12, 26), :ie)
14
- assert_equal 'St. Stephen\'s Day', h[0][:name]
15
-
16
- h = Holidays.on(Date.new(2008, 5, 9), :gb_)
17
- assert_equal 'Liberation Day', (h[0] || {})[:name]
18
-
19
- h = Holidays.on(Date.new(2008, 5, 9), :je)
20
- assert_equal 'Liberation Day', h[0][:name]
21
-
22
- h = Holidays.on(Date.new(2008, 5, 9), :gb)
23
- assert h.empty?
24
- end
25
-
26
- def test_north_american_parent_region_lookup
27
- assert_equal :ca, Holidays::PARENT_REGION_LOOKUP[:ca]
28
- assert_equal :ca, Holidays::PARENT_REGION_LOOKUP[:ca_qc]
29
- assert_equal :mx, Holidays::PARENT_REGION_LOOKUP[:mx]
30
- assert_equal :mx, Holidays::PARENT_REGION_LOOKUP[:mx_pue]
31
- assert_equal :us, Holidays::PARENT_REGION_LOOKUP[:us]
32
- assert_equal :us, Holidays::PARENT_REGION_LOOKUP[:us_fl]
33
- end
34
-
35
- def test_north_american_subregion_caching
36
- { ca: :ca_qc, mx: :mx_pue, us: :us_fl }.each do |region, subregion|
37
- module_name = region.upcase
38
-
39
- reset_cache
40
- Holidays.on(Date.new(2018, 1, 1), region) # Test check on regional holidays
41
- assert_equal [region], Holidays::Factory::Definition.regions_repository.all_loaded, "Only Holidays::#{module_name} should be loaded"
42
- holiday_regions = Holidays::Factory::Definition.holidays_by_month_repository.all.values.flatten.map { |h| h[:regions] }.uniq.flatten
43
- assert_includes holiday_regions, region, 'Region holidays should be loaded'
44
- assert_includes holiday_regions, subregion, 'Subregion holidays should be loaded'
45
-
46
- reset_cache
47
- Holidays.on(Date.new(2018, 1, 1), subregion) # Test check on subregional holidays
48
- assert_equal [region], Holidays::Factory::Definition.regions_repository.all_loaded, "Only Holidays::#{module_name} should be loaded"
49
- holiday_regions = Holidays::Factory::Definition.holidays_by_month_repository.all.values.flatten.map { |h| h[:regions] }.uniq.flatten
50
- assert_includes holiday_regions, region, 'Region holidays should be loaded'
51
- assert_includes holiday_regions, subregion, 'Subregion holidays should be loaded'
52
- end
53
- end
54
-
55
- def test_north_american_cross_region_caching
56
- reset_cache
57
- Holidays.on(Date.new(2018, 1, 1), :us)
58
- assert_equal [:us], Holidays::Factory::Definition.regions_repository.all_loaded, 'Only Holidays::US should be loaded'
59
- holiday_regions = Holidays::Factory::Definition.holidays_by_month_repository.all.values.flatten.map { |h| h[:regions] }.uniq.flatten
60
- assert_includes holiday_regions, :us, 'Region holidays should be loaded'
61
- assert_includes holiday_regions, :us_fl, 'Subregion holidays should be loaded'
62
-
63
- Holidays.on(Date.new(2018, 1, 1), :ca)
64
- assert_equal [:us, :ca], Holidays::Factory::Definition.regions_repository.all_loaded, 'Only Holidays::US and Holidays::CA should be loaded'
65
- holiday_regions = Holidays::Factory::Definition.holidays_by_month_repository.all.values.flatten.map { |h| h[:regions] }.uniq.flatten
66
- assert_includes holiday_regions, :us, 'Region holidays should be loaded'
67
- assert_includes holiday_regions, :ca, 'Region holidays should be loaded'
68
- assert_includes holiday_regions, :us_fl, 'Subregion holidays should be loaded'
69
- assert_includes holiday_regions, :ca_qc, 'Subregion holidays should be loaded'
70
- end
71
- end