holidays 6.4.0 → 8.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.gitmodules +1 -1
  3. data/CHANGELOG.md +80 -0
  4. data/Makefile +17 -4
  5. data/README.md +236 -101
  6. data/Rakefile +1 -1
  7. data/bin/console +0 -0
  8. data/bin/setup +1 -0
  9. data/doc/CONTRIBUTING.md +72 -0
  10. data/{MAINTAINERS.md → doc/MAINTAINERS.md} +5 -6
  11. data/{REFERENCES → doc/REFERENCES} +0 -0
  12. data/holidays.gemspec +8 -9
  13. data/lib/generated_definitions/MANIFEST +12 -4
  14. data/lib/generated_definitions/REGIONS.rb +2 -2
  15. data/lib/generated_definitions/ar.rb +30 -11
  16. data/lib/generated_definitions/at.rb +2 -2
  17. data/lib/generated_definitions/au.rb +26 -8
  18. data/lib/generated_definitions/be_fr.rb +2 -2
  19. data/lib/generated_definitions/be_nl.rb +2 -2
  20. data/lib/generated_definitions/bg.rb +2 -2
  21. data/lib/generated_definitions/br.rb +2 -2
  22. data/lib/generated_definitions/ca.rb +24 -17
  23. data/lib/generated_definitions/ch.rb +16 -4
  24. data/lib/generated_definitions/cl.rb +7 -10
  25. data/lib/generated_definitions/co.rb +121 -0
  26. data/lib/generated_definitions/cr.rb +2 -2
  27. data/lib/generated_definitions/cz.rb +2 -2
  28. data/lib/generated_definitions/de.rb +8 -5
  29. data/lib/generated_definitions/dk.rb +2 -2
  30. data/lib/generated_definitions/{ecb_target.rb → ecbtarget.rb} +10 -10
  31. data/lib/generated_definitions/ee.rb +2 -2
  32. data/lib/generated_definitions/el.rb +2 -2
  33. data/lib/generated_definitions/es.rb +8 -5
  34. data/lib/generated_definitions/europe.rb +114 -29
  35. data/lib/generated_definitions/federalreserve.rb +35 -0
  36. data/lib/generated_definitions/{federal_reserve.rb → federalreservebanks.rb} +15 -14
  37. data/lib/generated_definitions/fedex.rb +2 -2
  38. data/lib/generated_definitions/fi.rb +2 -2
  39. data/lib/generated_definitions/fr.rb +2 -2
  40. data/lib/generated_definitions/gb.rb +15 -8
  41. data/lib/generated_definitions/ge.rb +2 -2
  42. data/lib/generated_definitions/hk.rb +2 -2
  43. data/lib/generated_definitions/hr.rb +10 -8
  44. data/lib/generated_definitions/hu.rb +4 -3
  45. data/lib/generated_definitions/ie.rb +2 -2
  46. data/lib/generated_definitions/is.rb +2 -2
  47. data/lib/generated_definitions/it.rb +16 -7
  48. data/lib/generated_definitions/jp.rb +34 -15
  49. data/lib/generated_definitions/kr.rb +2 -2
  50. data/lib/generated_definitions/kz.rb +38 -0
  51. data/lib/generated_definitions/li.rb +2 -2
  52. data/lib/generated_definitions/lt.rb +2 -2
  53. data/lib/generated_definitions/lu.rb +4 -2
  54. data/lib/generated_definitions/lv.rb +55 -0
  55. data/lib/generated_definitions/ma.rb +2 -2
  56. data/lib/generated_definitions/mt_en.rb +2 -2
  57. data/lib/generated_definitions/mt_mt.rb +2 -2
  58. data/lib/generated_definitions/mx.rb +7 -7
  59. data/lib/generated_definitions/my.rb +2 -2
  60. data/lib/generated_definitions/nerc.rb +2 -2
  61. data/lib/generated_definitions/ng.rb +33 -0
  62. data/lib/generated_definitions/nl.rb +2 -2
  63. data/lib/generated_definitions/no.rb +2 -2
  64. data/lib/generated_definitions/{north_america.rb → northamerica.rb} +33 -26
  65. data/lib/generated_definitions/nyse.rb +3 -2
  66. data/lib/generated_definitions/nz.rb +41 -3
  67. data/lib/generated_definitions/pe.rb +2 -2
  68. data/lib/generated_definitions/ph.rb +2 -2
  69. data/lib/generated_definitions/pl.rb +2 -2
  70. data/lib/generated_definitions/pt.rb +2 -2
  71. data/lib/generated_definitions/ro.rb +6 -3
  72. data/lib/generated_definitions/rs_cyrl.rb +3 -3
  73. data/lib/generated_definitions/rs_la.rb +3 -3
  74. data/lib/generated_definitions/ru.rb +2 -2
  75. data/lib/generated_definitions/scandinavia.rb +2 -2
  76. data/lib/generated_definitions/se.rb +2 -2
  77. data/lib/generated_definitions/sg.rb +2 -2
  78. data/lib/generated_definitions/si.rb +4 -3
  79. data/lib/generated_definitions/sk.rb +2 -2
  80. data/lib/generated_definitions/southamerica.rb +247 -0
  81. data/lib/generated_definitions/th.rb +36 -0
  82. data/lib/generated_definitions/tn.rb +2 -2
  83. data/lib/generated_definitions/tr.rb +7 -5
  84. data/lib/generated_definitions/ua.rb +37 -0
  85. data/lib/generated_definitions/{united_nations.rb → unitednations.rb} +61 -61
  86. data/lib/generated_definitions/ups.rb +2 -2
  87. data/lib/generated_definitions/us.rb +9 -9
  88. data/lib/generated_definitions/ve.rb +2 -2
  89. data/lib/generated_definitions/vi.rb +2 -2
  90. data/lib/generated_definitions/za.rb +3 -3
  91. data/lib/holidays/core_extensions/time.rb +3 -3
  92. data/lib/holidays/definition/context/generator.rb +23 -70
  93. data/lib/holidays/definition/context/load.rb +1 -1
  94. data/lib/holidays/definition/generator/module.rb +54 -0
  95. data/lib/holidays/definition/generator/regions.rb +7 -2
  96. data/lib/holidays/definition/parser/custom_method.rb +2 -2
  97. data/lib/holidays/definition/repository/cache.rb +2 -1
  98. data/lib/holidays/definition/repository/holidays_by_month.rb +9 -1
  99. data/lib/holidays/factory/definition.rb +7 -0
  100. data/lib/holidays/finder/context/between.rb +6 -7
  101. data/lib/holidays/finder/context/dates_driver_builder.rb +5 -11
  102. data/lib/holidays/finder/context/next_holiday.rb +12 -12
  103. data/lib/holidays/finder/context/parse_options.rb +0 -6
  104. data/lib/holidays/finder/context/search.rb +39 -32
  105. data/lib/holidays/finder/rules/year_range.rb +30 -54
  106. data/lib/holidays/version.rb +1 -1
  107. data/lib/holidays.rb +14 -7
  108. data/test/coverage_report.rb +23 -7
  109. data/test/data/test_custom_informal_holidays_defs.yaml +11 -0
  110. data/test/data/test_custom_year_range_holiday_defs.yaml +6 -10
  111. data/test/data/test_multiple_regions_with_conflicts_region_1.yaml +38 -0
  112. data/test/data/test_multiple_regions_with_conflicts_region_2.yaml +38 -0
  113. data/test/defs/test_defs_ar.rb +30 -6
  114. data/test/defs/test_defs_at.rb +5 -3
  115. data/test/defs/test_defs_au.rb +29 -0
  116. data/test/defs/test_defs_be_fr.rb +10 -0
  117. data/test/defs/test_defs_be_nl.rb +10 -0
  118. data/test/defs/test_defs_ca.rb +63 -8
  119. data/test/defs/test_defs_ch.rb +6 -0
  120. data/test/defs/test_defs_co.rb +113 -0
  121. data/test/defs/test_defs_de.rb +7 -1
  122. data/test/defs/{test_defs_ecb_target.rb → test_defs_ecbtarget.rb} +11 -11
  123. data/test/defs/test_defs_es.rb +2 -0
  124. data/test/defs/test_defs_europe.rb +250 -15
  125. data/test/defs/test_defs_federalreserve.rb +119 -0
  126. data/test/defs/test_defs_federalreservebanks.rb +251 -0
  127. data/test/defs/test_defs_gb.rb +42 -0
  128. data/test/defs/test_defs_hr.rb +6 -6
  129. data/test/defs/test_defs_hu.rb +12 -4
  130. data/test/defs/test_defs_it.rb +20 -0
  131. data/test/defs/test_defs_jp.rb +30 -2
  132. data/test/defs/test_defs_kz.rb +39 -0
  133. data/test/defs/test_defs_lu.rb +6 -0
  134. data/test/defs/test_defs_lv.rb +96 -0
  135. data/test/defs/test_defs_mx.rb +3 -1
  136. data/test/defs/test_defs_ng.rb +29 -0
  137. data/test/defs/{test_defs_north_america.rb → test_defs_northamerica.rb} +77 -20
  138. data/test/defs/test_defs_nyse.rb +7 -0
  139. data/test/defs/test_defs_nz.rb +4 -0
  140. data/test/defs/test_defs_ro.rb +14 -0
  141. data/test/defs/test_defs_rs_cyrl.rb +1 -1
  142. data/test/defs/test_defs_rs_la.rb +1 -1
  143. data/test/defs/test_defs_southamerica.rb +323 -0
  144. data/test/defs/test_defs_th.rb +33 -0
  145. data/test/defs/test_defs_tr.rb +7 -0
  146. data/test/defs/test_defs_ua.rb +41 -0
  147. data/test/defs/{test_defs_united_nations.rb → test_defs_unitednations.rb} +3 -3
  148. data/test/defs/test_defs_us.rb +11 -11
  149. data/test/holidays/core_extensions/test_date.rb +3 -2
  150. data/test/holidays/definition/context/test_generator.rb +17 -20
  151. data/test/holidays/definition/context/test_load.rb +3 -3
  152. data/test/holidays/definition/generator/test_module.rb +268 -0
  153. data/test/holidays/definition/parser/test_custom_method.rb +4 -4
  154. data/test/holidays/definition/repository/test_holidays_by_month.rb +121 -1
  155. data/test/holidays/finder/context/test_parse_options.rb +0 -10
  156. data/test/holidays/finder/rules/test_year_range.rb +43 -47
  157. data/test/integration/test_any_holidays_during_work_week.rb +90 -0
  158. data/test/integration/test_available_regions.rb +1 -1
  159. data/test/integration/test_custom_informal_holidays.rb +15 -0
  160. data/test/integration/test_custom_year_range_holidays.rb +0 -7
  161. data/test/integration/test_holidays.rb +4 -56
  162. data/test/integration/test_holidays_between.rb +11 -1
  163. data/test/integration/test_multiple_regions.rb +54 -6
  164. data/test/integration/test_multiple_regions_with_conflict.rb +29 -0
  165. data/test/integration/test_nonstandard_regions.rb +25 -0
  166. metadata +79 -53
  167. data/CONTRIBUTING.md +0 -51
  168. data/test/defs/test_defs_federal_reserve.rb +0 -111
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 211587fa0f6cc9770aa844987375a9c4494f9268
4
- data.tar.gz: 195e0a198d61ded54df5dd59b19abedbf54b0e48
2
+ SHA256:
3
+ metadata.gz: 9eb1a9a2387a3734d10203b125345004d0c470ccc2394b82e36f57277a487db0
4
+ data.tar.gz: 9a77c89d65379366e70b9d6e3eed67080ce5fadb096c11dad1b5edb81dee2e8c
5
5
  SHA512:
6
- metadata.gz: 819cc7b8eca33162c12031432f60d91b2f9d848a26c385d2c126b810b5534ab3279408a025d4571d7700d0a3ad15f3694454d2180c44f0cb2d67607d64185a01
7
- data.tar.gz: 1463973d2d30e143217e2049c8a353c6cf8582051b7007cde8e27d252c40a4016a2a772c4714be05c60ca8c2b8c226f8891f625ffa44d17126088decfdfebe48
6
+ metadata.gz: 5580b2c4ed9f227fc68558382fa2635df1fb234291b7bd554f3675bea59cf81345be20de1cc7fa8babb9cd445cf1d076dde9eebed1947d75a5a956fdf2ae2158
7
+ data.tar.gz: 210b384735179c141e9c15d0de847449a3e70cd7e468453afd9b038afced110c1ea957b69d48e1196e524a2da3804af1d3502558407f4a9b71e998fb9ae3da64
data/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
1
  [submodule "definitions"]
2
2
  path = definitions
3
- url = https://github.com/holidays/definitions
3
+ url = https://github.com/holidays/definitions
data/CHANGELOG.md CHANGED
@@ -1,5 +1,85 @@
1
1
  # Ruby Holidays Gem CHANGELOG
2
2
 
3
+ ## 8.6.0
4
+
5
+ * Update to [v5.5.0 definitions](https://github.com/holidays/definitions/releases/tag/v5.5.0). Please see the changelog for the definition details.
6
+ * Temporarily remove jruby from required jobs due to test coverage issues
7
+
8
+ ## 8.5.0
9
+
10
+ * Update submodule definitions.
11
+ * Thanks to contributors!!
12
+
13
+ ## 8.4.1
14
+
15
+ * Fix jp holidays from 2022.
16
+
17
+ ## 8.4.0
18
+
19
+ * Update submodule definitions.
20
+ * Thanks to contributors!!
21
+
22
+
23
+ ## 8.3.0
24
+
25
+ * Update submodule definitions.
26
+ * Remove test about feb 29 on non leap year.
27
+ * Thanks to contributors!!
28
+
29
+ ## 8.2.0
30
+
31
+ * Update submodule definitions. Thanks to contributors!!
32
+
33
+ ## 8.1.0
34
+
35
+ * Update submodule definitions, so that the newest holidays from the definition
36
+ gem are represent here.
37
+
38
+ ## 8.0.0
39
+
40
+ * Remove support for ruby 2.2 and ruby 2.3.
41
+ * Add support for latest ruby 2.6
42
+ * Update to [v5.0.1 definitions](https://github.com/holidays/definitions/releases/tag/v5.0.1). Please see the changelog for the definition details.
43
+
44
+ ## 7.1.0
45
+
46
+ * Update to [v4.1.0 definitions](https://github.com/holidays/definitions/releases/tag/v4.1.0). Please see the changelog for the definition details.
47
+
48
+ ## 7.0.0
49
+
50
+ Major semver bump due to the major version change in the [definitions](https://github.com/holidays/definitions/blob/master/CHANGELOG.md#400). Several non ISO regions have been modified in order to provide more clarity for parent and sub-regions.
51
+
52
+ Affected regions:
53
+
54
+ * `ecb_target` region changed to `ecbtarget`
55
+ * `federal_reserve` region changed to `federalreserve`
56
+ * `federalreservebanks` region changed to `federalreservebanks`
57
+ * `north_america_informal` region changed to `northamericainformal`
58
+ * `united_nations` region changed to `unitednations`
59
+ * `north_america` region changed to `northamerica`
60
+ * `south_america` region changed to `southamerica`
61
+
62
+ Please see the [definitions v4.0.0 CHANGELOG](https://github.com/holidays/definitions/blob/master/CHANGELOG.md#400) for the full change list.
63
+
64
+ ## 6.6.1
65
+
66
+ * Fixes `any_holidays_during_work_week?` so that it actually does what it says it does [issue-264](https://github.com/holidays/holidays/issues/264)
67
+
68
+ ## 6.6.0
69
+
70
+ * Update to [v3.0.0 definitions](https://github.com/holidays/definitions/releases/tag/v3.0.0). This required updates to the custom method parser but no behavior changes.
71
+ * Remove unused `simplecov-rcov` from gemspec dev dependencies
72
+ * Fix parent region loading bug [PR](https://github.com/holidays/holidays/pull/320) (thanks to chadrschroeder)
73
+ * Fix `ruby-head` build caused by new 'endless range' feature in ruby 2.6.0 [PR](https://github.com/holidays/holidays/pull/321)
74
+ * Refactor definition search logic for improved readability [PR](https://github.com/holidays/holidays/pull/318) (thanks to https://github.com/guizma)
75
+ * Reorganize most documentation into the `docs/` directory
76
+ * Fix list of covered rubies in README
77
+
78
+ ## 6.5.0
79
+
80
+ * Update to [v2.5.2 definitions](https://github.com/holidays/definitions/releases/tag/v2.5.2). Please see the changelog for the definition details.
81
+ * Fix permissions on `bin` executables (thanks to github.com/JuanitoFatas)
82
+
3
83
  ## 6.4.0
4
84
 
5
85
  * Update to [v2.4.0 definitions](https://github.com/holidays/definitions/releases/tag/v2.4.0). Please see the changelog for the definition details.
data/Makefile CHANGED
@@ -1,6 +1,6 @@
1
1
  default: test
2
2
 
3
- setup: update_defs
3
+ setup: update-defs
4
4
  bundle install
5
5
 
6
6
  generate:
@@ -12,7 +12,7 @@ test:
12
12
  console:
13
13
  bundle exec rake console
14
14
 
15
- test_region:
15
+ test-region:
16
16
  bundle exec rake test_region $(REGION)
17
17
 
18
18
  build: clean
@@ -21,12 +21,25 @@ build: clean
21
21
  push:
22
22
  bundle exec gem push $(GEM)
23
23
 
24
- update_defs:
24
+ update-defs: definitions/
25
25
  git submodule update --init --remote --recursive
26
26
 
27
+ definitions: point-to-defs-master
28
+
29
+ point-to-defs-branch:
30
+ git submodule add -b $(BRANCH) git@github.com:$(USER)/definitions.git definitions/
31
+
32
+ point-to-defs-master:
33
+ git submodule add https://github.com/holidays/definitions definitions/
34
+
35
+ clean-defs:
36
+ git rm -f definitions
37
+ rm -rf .git/modules/definitions
38
+ git config -f .git/config --remove-section submodule.definitions 2> /dev/null
39
+
27
40
  clean:
28
41
  rm -rf holidays-*.gem
29
42
  rm -rf reports
30
43
  rm -rf coverage
31
44
 
32
- .PHONY: setup test generate
45
+ .PHONY: setup test generate console build push update-defs test-region clean-defs point-to-defs-master point-to-defs-branch clean definitions
data/README.md CHANGED
@@ -1,183 +1,318 @@
1
1
  # Ruby Holidays Gem [![Build Status](https://travis-ci.org/holidays/holidays.svg?branch=master)](https://travis-ci.org/holidays/holidays)
2
2
 
3
- A set of functions to deal with holidays in Ruby.
3
+ Functionality to deal with holidays in Ruby.
4
4
 
5
- Extends Ruby's built-in Date class and supports custom holiday definition lists.
6
-
7
- Full documentation can be found [here](http://www.rubydoc.info/github/alexdunae/holidays/master/frames).
5
+ Extends Ruby's built-in Date and Time classes and supports custom holiday definition lists.
8
6
 
9
7
  ## Installation
10
8
 
11
- To install the gem from RubyGems:
9
+ ```
10
+ gem install holidays
11
+ ```
12
+
13
+ ## Tested versions
14
+
15
+ This gem is tested with the following ruby versions:
16
+
17
+ * 2.4.5
18
+ * 2.5.3
19
+ * 2.6.1
20
+ * JRuby 9.2.5.0
12
21
 
13
- gem install holidays
22
+ ## Semver
14
23
 
15
- The Holidays gem is tested on Ruby 2.2.0, 2.3.0, 2.4.0 and JRuby.
24
+ This gem follows [semantic versioning](http://semver.org/). The guarantee specifically covers:
16
25
 
17
- This gem follows [semantic versioning](http://semver.org/). The only methods covered by this guarantee are under the
18
- `Holidays` namespace specifically. Anything that is not a method off of `Holidays` or the core extension is not covered by
19
- semver. Please take this into account when relying on this gem as a dependency.
26
+ * methods in the top-most `Holidays` namespace e.g. `Holidays.<method>`
27
+ * the [core extensions](#extending-rubys-date-and-time-classes)
20
28
 
21
- Also note that we consider definition changes as 'minor' bumps, meaning they are backwards compatible with your code
22
- but might give different holiday results!
29
+ Please note that we consider definition changes to be 'minor' bumps, meaning they are backwards compatible with your code but might give different holiday results!
23
30
 
24
31
  ## Time zones
25
32
 
26
33
  Time zones are ignored. This library assumes that all dates are within the same time zone.
27
34
 
28
- ### Using the Holidays class
35
+ ## Usage
29
36
 
30
- Get all holidays on April 25, 2008 in Australia.
37
+ This gem offers multiple ways to check for holidays for a variety of scenarios.
31
38
 
32
- date = Date.civil(2008,4,25)
39
+ #### Checking a specific date
33
40
 
34
- Holidays.on(date, :au)
35
- => [{:name => 'ANZAC Day',...}]
41
+ Get all holidays on April 25, 2008 in Australia:
36
42
 
37
- Get holidays that are observed on July 2, 2007 in British Columbia, Canada.
43
+ ```
44
+ Holidays.on(Date.civil(2008, 4, 25), :au)
45
+ => [{:name => 'ANZAC Day',...}]
46
+ ```
38
47
 
39
- date = Date.civil(2007,7,2)
48
+ You can check multiple regions in a single call:
40
49
 
41
- Holidays.on(date, :ca_bc, :observed)
42
- => [{:name => 'Canada Day',...}]
50
+ ```
51
+ Holidays.on(Date.civil(2008, 1, 1), :us, :fr)
52
+ => [{:name=>"New Year's Day", :regions=>[:us],...},
53
+ {:name=>"Jour de l'an", :regions=>[:fr],...}]
54
+ ```
43
55
 
44
- Get all holidays in July, 2008 in Canada and the US.
56
+ You can leave off 'regions' to get holidays for any region in our [definitions](https://github.com/holidays/definitions):
45
57
 
46
- from = Date.civil(2008,7,1)
47
- to = Date.civil(2008,7,31)
58
+ ```
59
+ Holidays.on(Date.civil(2007, 4, 25))
60
+ => [{:name=>"ANZAC Day", :regions=>[:au],...},
61
+ {:name=>"Festa della Liberazione", :regions=>[:it],...},
62
+ {:name=>"Dia da Liberdade", :regions=>[:pt],...}
63
+ ...
64
+ ]
65
+ ```
48
66
 
49
- Holidays.between(from, to, :ca, :us)
50
- => [{:name => 'Canada Day',...}
51
- {:name => 'Independence Day',...}]
67
+ #### Checking a date range
52
68
 
53
- Get all US Federal holidays between 2018 and 2019.
69
+ Get all holidays during the month of July 2008 in Canada and the US:
54
70
 
55
- from = Date.civil(2018,1,1)
56
- to = Date.civil(2019,12,31)
71
+ ```
72
+ from = Date.civil(2008,7,1)
73
+ to = Date.civil(2008,7,31)
57
74
 
58
- Holidays.between(from, to, :federal_reserve, :observed)
59
- => [{:name => "New Year's Day"....}
60
- {:name => "Birthday of Martin Luther King, Jr"....}]
75
+ Holidays.between(from, to, :ca, :us)
76
+ => [{:name => 'Canada Day',...}
77
+ {:name => 'Independence Day',...}]
78
+ ```
61
79
 
62
- Get informal holidays in February.
80
+ #### Check for 'informal' holidays
63
81
 
64
- from = Date.civil(2008,2,1)
65
- to = Date.civil(2008,2,15)
82
+ You can pass the 'informal' flag to include holidays specified as informal in your results. See [here](https://github.com/holidays/definitions/blob/master/doc/SYNTAX.md#formalinformal) for information on what constitutes 'informal' vs 'formal'.
66
83
 
67
- Holidays.between(from, to, :informal)
68
- => [{:name => 'Valentine\'s Day',...}]
84
+ By default this flag is turned off, meaning no informal holidays will be returned.
69
85
 
70
- Return all available regions:
86
+ Get Valentine's Day in the US:
87
+
88
+ ```
89
+ Holidays.on(Date.new(2018, 2, 14), :us, :informal)
90
+ => [{:name=>"Valentine's Day",...}]
91
+ ```
92
+
93
+ Leaving off 'informal' will mean that Valentine's Day is not returned:
94
+
95
+ ```
96
+ Holidays.on(Date.new(2018, 2, 14), :us)
97
+ => []
98
+ ```
99
+
100
+ Get informal holidays during the month of February 2008 for any region:
101
+
102
+ ```
103
+ from = Date.civil(2008,2,1)
104
+ to = Date.civil(2008,2,15)
105
+
106
+ Holidays.between(from, to, :informal)
107
+ => [{:name => 'Valentine\'s Day',...}]
108
+ ```
109
+
110
+ #### Check for 'observed' holidays
111
+
112
+ You can pass the 'observed' flag to include holidays that are observed on different days than they actually occur. See [here](https://github.com/holidays/definitions/blob/master/doc/SYNTAX.md#observed) for further explanation of 'observed'.
113
+
114
+ By default this flag is turned off, meaning no observed logic will be applied.
115
+
116
+ Get holidays that are observed on Monday July 2, 2007 in British Columbia, Canada:
117
+
118
+ ```
119
+ Holidays.on(Date.civil(2007, 7, 2), :ca_bc, :observed)
120
+ => [{:name => 'Canada Day',...}]
121
+ ```
71
122
 
72
- Holidays.available_regions
73
- => [:ar, :at, ..., :sg] # this will be a big array
123
+ Leaving off the 'observed' flag will mean that 'Canada Day' is not returned since it actually falls on Sunday July 1:
74
124
 
75
- To check if there are any holidays taking place during a specified work week:
125
+ ```
126
+ Holidays.on(Date.civil(2007, 7, 2), :ca_bc)
127
+ => []
128
+ Holidays.on(Date.civil(2007, 7, 1), :ca_bc)
129
+ => [{:name=>"Canada Day", :regions=>[:ca],...}]
130
+ ```
76
131
 
77
- Holidays.any_holidays_during_work_week?(Date.civil(2016, 1, 1))
78
- => true
132
+ Get all observed US Federal holidays between 2018 and 2019:
79
133
 
80
- To find and return the next holidays occurring from date, inclusively:
134
+ ```
135
+ from = Date.civil(2018,1,1)
136
+ to = Date.civil(2019,12,31)
81
137
 
82
- Holidays.next_holidays(3, [:us, :informal], Date.civil(2016, 2, 23))
83
- => [{:name => "St. Patrick's Day",...}, {:name => "Good Friday",...}, {:name => "Easter Sunday",...}]
138
+ Holidays.between(from, to, :federalreserve, :observed)
139
+ => [{:name => "New Year's Day"....}
140
+ {:name => "Birthday of Martin Luther King, Jr"....}]
141
+ ```
84
142
 
85
- Will default to `Date.today` if no date is provided.
143
+ #### Check whether any holidays occur during work week
86
144
 
87
- To find all holidays occuring from date to end of year, inclusively:
145
+ Check if there are any holidays taking place during a specified work week. 'Work week' is defined as the period of Monday through Friday of the week specified by the date.
88
146
 
89
- Holidays.year_holidays([:ca_on], Date.civil(2016, 2, 23))
90
- => [{:name=>"Good Friday",...},
91
- {name=>"Easter Sunday",...},
92
- {:name=>"Victoria Day",...},
93
- {:name=>"Canada Day",...},
94
- {:name=>"Civic Holiday",...},
95
- {:name=>"Labour Day",...},
96
- {:name=>"Thanksgiving",...},
97
- {:name=>"Remembrance Day",...},
98
- {:name=>"Christmas Day",...},
99
- {:name=>"Boxing Day",...}]
147
+ Check whether a holiday falls during first week of the year for any region:
100
148
 
101
- Will default to `Date.today` if no date is provided.
149
+ ```
150
+ Holidays.any_holidays_during_work_week?(Date.civil(2016, 1, 1))
151
+ => true
152
+ ```
102
153
 
103
- ### Loading Custom Definitions on the fly
154
+ You can also pass in `informal` or `observed`:
104
155
 
105
- Load custom definitions file on the fly and use them immediately.
156
+ ```
157
+ # Returns true since Valentine's Day falls on a Wednesday
158
+ holidays.any_holidays_during_work_week?(date.civil(2018, 2, 14), :us, :informal)
159
+ => true
160
+ # Returns false if you don't specify informal
161
+ irb(main):006:0> Holidays.any_holidays_during_work_week?(Date.civil(2018, 2, 14), :us)
162
+ => false
163
+ # Returns true since Veteran's Day is observed on Monday November 12, 2018
164
+ holidays.any_holidays_during_work_week?(date.civil(2018, 11, 12), :us, :observed)
165
+ => true
166
+ # Returns false if you don't specify observed since the actual holiday is on Sunday November 11th 2018
167
+ irb(main):005:0> Holidays.any_holidays_during_work_week?(Date.civil(2018, 11, 12), :us)
168
+ => false
169
+ ```
106
170
 
107
- Load custom 'Company Founding' holiday on June 1st:
171
+ #### Find the next holiday(s) that will occur from a specific date
108
172
 
109
- Holidays.load_custom('/home/user/holiday_definitions/custom_holidays.yaml')
173
+ Get the next holidays occurring from February 23, 2016 for the US:
110
174
 
111
- date = Date.civil(2013,6,1)
175
+ ```
176
+ Holidays.next_holidays(3, [:us, :informal], Date.civil(2016, 2, 23))
177
+ => [{:name => "St. Patrick's Day",...}, {:name => "Good Friday",...}, {:name => "Easter Sunday",...}]
178
+ ```
112
179
 
113
- Holidays.on(date, :my_custom_region)
114
- => [{:name => 'Company Founding',...}]
180
+ You can specify the number of holidays to return. This method will default to `Date.today` if no date is provided.
115
181
 
116
- Custom definition files must match the format of the existing definition YAML files location in the 'definitions' directory.
182
+ #### Find all holidays occuring starting from a specific date to the end of the year
117
183
 
118
- Multiple files can also be passed:
184
+ Get all holidays starting from February 23, 2016 to end of year in the US:
119
185
 
120
- Holidays.load_custom('/home/user/holidays/custom_holidays1.yaml', '/home/user/holidays/custom_holidays2.yaml')
186
+ ```
187
+ Holidays.year_holidays([:ca_on], Date.civil(2016, 2, 23))
188
+ => [{:name=>"Good Friday",...},
189
+ {name=>"Easter Sunday",...},
190
+ {:name=>"Victoria Day",...},
191
+ {:name=>"Canada Day",...},
192
+ {:name=>"Civic Holiday",...},
193
+ {:name=>"Labour Day",...},
194
+ {:name=>"Thanksgiving",...},
195
+ {:name=>"Remembrance Day",...},
196
+ {:name=>"Christmas Day",...},
197
+ {:name=>"Boxing Day",...}]
198
+ ```
121
199
 
122
- ### Extending Ruby's Date and Time classes
200
+ This method will default to `Date.today` if no date is provided.
201
+
202
+ #### Return all available regions
203
+
204
+ Return all available regions:
205
+
206
+ ```
207
+ Holidays.available_regions
208
+ => [:ar, :at, ..., :sg] # this will be a big array
209
+ ```
210
+
211
+ ## Loading Custom Definitions on the fly
212
+
213
+ In addition to the [provided definitions](https://github.com/holidays/definitions) you can load custom definitions file on the fly and use them immediately.
214
+
215
+ To load custom 'Company Founding' holiday on June 1st:
216
+
217
+ ```
218
+ Holidays.load_custom('/home/user/holiday_definitions/custom_holidays.yaml')
219
+ Holidays.on(Date.civil(2013, 6, 1), :my_custom_region)
220
+ => [{:name => 'Company Founding',...}]
221
+ ```
222
+
223
+ Custom definition files must match the [syntax of the existing definition files](https://github.com/holidays/definitions/blob/master/doc/SYNTAX.md).
224
+
225
+ Multiple files can be loaded at the same time:
226
+
227
+ ```
228
+ Holidays.load_custom('/home/user/holidays/custom_holidays1.yaml', '/home/user/holidays/custom_holidays2.yaml')
229
+ ```
230
+
231
+ ## Extending Ruby's Date and Time classes
232
+
233
+ ### Date
123
234
 
124
235
  To extend the 'Date' class:
125
236
 
126
- require 'holidays/core_extensions/date'
127
- class Date
128
- include Holidays::CoreExtensions::Date
129
- end
237
+ ```
238
+ require 'holidays/core_extensions/date'
239
+ class Date
240
+ include Holidays::CoreExtensions::Date
241
+ end
242
+ ```
130
243
 
131
244
  Now you can check which holidays occur in Iceland on January 1, 2008:
132
245
 
133
- d = Date.civil(2008,7,1)
246
+ ```
247
+ d = Date.civil(2008,7,1)
134
248
 
135
- d.holidays(:is)
136
- => [{:name => 'Nýársdagur'}...]
249
+ d.holidays(:is)
250
+ => [{:name => 'Nýársdagur'}...]
251
+ ```
137
252
 
138
253
  Or lookup Canada Day in different regions:
139
254
 
140
- d = Date.civil(2008,7,1)
255
+ ```
256
+ d = Date.civil(2008,7,1)
141
257
 
142
- d.holiday?(:ca) # Canada
143
- => true
258
+ d.holiday?(:ca) # Canada
259
+ => true
144
260
 
145
- d.holiday?(:ca_bc) # British Columbia, Canada
146
- => true
261
+ d.holiday?(:ca_bc) # British Columbia, Canada
262
+ => true
147
263
 
148
- d.holiday?(:fr) # France
149
- => false
264
+ d.holiday?(:fr) # France
265
+ => false
266
+ ```
150
267
 
151
268
  Or return the new date based on the options:
152
269
 
153
- d = Date.civil(2008,7,1)
154
- d.change(:year => 2016, :month => 1, :day => 1)
155
- => #<Date: 2016-01-01 ((2457389j,0s,0n),+0s,2299161j)>
270
+ ```
271
+ d = Date.civil(2008,7,1)
272
+ d.change(:year => 2016, :month => 1, :day => 1)
273
+ => #<Date: 2016-01-01 ((2457389j,0s,0n),+0s,2299161j)>
274
+ ```
156
275
 
157
276
  Or you can calculate the day of the month:
158
277
 
159
- Date.calculate_mday(2015, 4, :first, 2)
160
- => 7
278
+ ```
279
+ Date.calculate_mday(2015, 4, :first, 2)
280
+ => 7
281
+ ```
282
+
283
+ ### Time
284
+
285
+ ```
286
+ require 'holidays/core_extensions/time'
287
+ class Time
288
+ include Holidays::CoreExtensions::Time
289
+ end
290
+ ```
161
291
 
162
- Or find end of month for given date (requires 'Time' extensions as well):
292
+ Find end of month for given date:
163
293
 
164
- d = Date.civil(2016,8,1)
165
- d.end_of_month
166
- => #<Date: 2016-08-31 ((2457632j,0s,0n),+0s,2299161j)>
294
+ ```
295
+ d = Date.civil(2016,8,1)
296
+ d.end_of_month
297
+ => #<Date: 2016-08-31 ((2457632j,0s,0n),+0s,2299161j)>
298
+ ```
167
299
 
168
- ### Caching Holiday Lookups
300
+ ## Caching Holiday Lookups
169
301
 
170
- If you are checking holidays regularly you can cache your results for improved performance. Run this before looking up a holiday (eg. in an initializer):
302
+ If you are checking holidays regularly you can cache your results for improved performance. Run this before looking up a holiday (e.g. in an initializer):
171
303
 
172
- Holidays.cache_between(Time.now, 2.years.from_now, :ca, :us, :observed)
304
+ ```
305
+ YEAR = 365 * 24 * 60 * 60
306
+ Holidays.cache_between(Time.now, Time.now + 2 * YEAR, :ca, :us, :observed)
307
+ ```
173
308
 
174
309
  Holidays for the regions specified within the dates specified will be pre-calculated and stored in-memory. Future lookups will be much faster.
175
310
 
176
- ### How to contribute
311
+ ## How to contribute
177
312
 
178
- See our [contribution guidelines](CONTRIBUTING.md) for information on how to help out!
313
+ See our [contribution guidelines](doc/CONTRIBUTING.md) for information on how to help out!
179
314
 
180
- ### Credits and code
315
+ ## Credits and code
181
316
 
182
317
  * Started by [@alexdunae](http://github.com/alexdunae) 2007-2012
183
318
  * Maintained by [@hahahana](https://github.com/hahahana), 2013
data/Rakefile CHANGED
@@ -41,7 +41,7 @@ end
41
41
 
42
42
  desc 'Launch IRB session'
43
43
  task :console do
44
- sh "irb -rubygems -I lib -r holidays.rb"
44
+ sh "irb -r rubygems -I lib -r holidays.rb"
45
45
  end
46
46
 
47
47
  desc 'Generate definitions and tests used in main holiday logic based on raw YAML definitions'
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/bin/bash
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
+ set -vx
4
5
 
5
6
  bundle install
@@ -0,0 +1,72 @@
1
+ # How to contribute
2
+
3
+ There are multiple ways to help! We rely on users around the world to help keep our definitions accurate and up to date. In addition, pull requests to address bugs or implement new features are always welcome.
4
+
5
+ ## Code of Conduct
6
+
7
+ Please read our [Code of Conduct](../CODE_OF_CONDUCT.md) before contributing. Everyone interacting with this project (or associated projects) is expected to abide by its terms.
8
+
9
+ ## General note
10
+
11
+ The definitions for this project are housed in a submodule. When pulling this repo please make sure to run `git clone --recursive git@github.com/holidays/holidays`
12
+ or, if you forgot to do so, run `make update-defs` so that all of the submodule data is pulled correctly.
13
+
14
+ ## For definition updates
15
+
16
+ Our definitions are written in YAML. They are housed in a [separate repository](https://github.com/holidays/definitions) so that they can be used by tools written in other languages. You can find a complete guide to our format in the [definitions SYNTAX guide](https://github.com/holidays/definitions/blob/master/doc/SYNTAX.md).
17
+
18
+ In this ruby project we take the YAML definitions and generate final ruby classes that are loaded at runtime for fast calculations.
19
+
20
+ Once you have a good idea on what you want to change, please see the [CONTRIBUTING guide](https://github.com/holidays/definitions/blob/master/doc/CONTRIBUTING.md) in the `definitions` repository.
21
+
22
+ The idea is that if the validation passes on the other repo then you shouldn't have to worry about generating and testing here. We'll see how that goes!
23
+
24
+ Once that PR is accepted the maintainers of this project will be responsible for generating the updated definitions here and releasing a new gem. Don't worry about versioning, we'll take care of it!
25
+
26
+ #### Testing out your definitions locally
27
+
28
+ As mentioned above we use a git submodule for the definitions. Sometimes you might want to manually test out how this ruby project will behave with your changes. To facilitate that we provide some commands for pointing the definitions submodule to your fork/branch.
29
+
30
+ To point at your fork/branch:
31
+
32
+ ```sh
33
+ make clean-defs
34
+ BRANCH=<branch-name> USER=<user> make point-to-defs-branch
35
+ ```
36
+
37
+ Example:
38
+
39
+ ```sh
40
+ make clean-defs
41
+ BRANCH=issue-24 USER=ppeble make point-to-defs-branch
42
+ ```
43
+
44
+ This will pull everything down for the latest commit on that fork/branch. When you are done testing and want to point back at the master definitions:
45
+
46
+ ```sh
47
+ make clean-defs
48
+ make point-to-defs-master
49
+ ```
50
+
51
+ ## For non-definition functionality
52
+
53
+ * Fork this repository
54
+ * Make your changes. Don't forget to run `make test` to execute the test suite!
55
+ * Create a PR pointing back to `master`
56
+
57
+ Don't worry about versioning, we'll handle it on our end.
58
+
59
+ *Tests are required*. If your PR results in lower test coverage then it will not be accepted.
60
+
61
+ ## Local development helpers
62
+
63
+ We have included a few handy tasks to help you troubleshoot and test:
64
+
65
+ * `make test` - runs the entire suite
66
+ * `bundle exec ruby <test-file-to-run>` - runs just the tests in the specified file
67
+ * `REGION=<region> make test-region` - runs the tests for just that region
68
+ * `make console` - launches an IRB session with the 'holidays' gem loaded for quick testing
69
+ * `make update-defs` - runs the appropriate git submodule commands to pull the latest definitions
70
+ * `make clean-defs` - removes the definitions submodule, useful for switching between a fork and the main definitions repository
71
+ * `BRANCH=<branch> USER=<user> make point-to-defs-branch` - updates your definitions submodule to point at a fork/branch
72
+ * `make point-to-defs-master` - updates your definitions submodule to point back at the `holidays/definitions` repo and master branch