holidays 6.6.0 → 6.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +233 -95
- data/holidays.gemspec +2 -2
- data/lib/generated_definitions/ch.rb +1 -1
- data/lib/generated_definitions/europe.rb +1 -1
- data/lib/holidays.rb +12 -7
- data/lib/holidays/core_extensions/time.rb +3 -3
- data/lib/holidays/finder/context/between.rb +6 -7
- data/lib/holidays/finder/context/next_holiday.rb +12 -12
- data/lib/holidays/version.rb +1 -1
- data/test/defs/test_defs_ch.rb +2 -0
- data/test/defs/test_defs_europe.rb +2 -0
- data/test/integration/test_any_holidays_during_work_week.rb +90 -0
- data/test/integration/test_holidays.rb +0 -24
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 844c8c66842896fceda5b386a64bcfd8d03d51781ebc328bc246ecdc6e41effc
|
4
|
+
data.tar.gz: 341f07eb7869fa24a501b1cc3380d36dc7a84fba5f3d70a3d821c53c560db416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 937db688aa9a3eb0b0bd928041eadbfc30b97cf0ffe92f2ee92bf92b160dc44fff196c6c3c84deb5a7cd3bfc8dbdaa2d4d2fb1a91dab83b59da726b7912f43bd
|
7
|
+
data.tar.gz: ba21c5e8ef10aa1507385c4cb62e531b9e9dc685190aa67dcd84753963726498828a4b46a9fabc2d4f090a1782bdcfa5325f0f1069214f383819d882d5b6e379
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Ruby Holidays Gem CHANGELOG
|
2
2
|
|
3
|
+
## 6.6.1
|
4
|
+
|
5
|
+
* 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)
|
6
|
+
|
3
7
|
## 6.6.0
|
4
8
|
|
5
9
|
* 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.
|
data/README.md
CHANGED
@@ -1,21 +1,31 @@
|
|
1
1
|
# Ruby Holidays Gem [](https://travis-ci.org/holidays/holidays)
|
2
2
|
|
3
|
-
|
3
|
+
Functionality to deal with holidays in Ruby.
|
4
4
|
|
5
|
-
Extends Ruby's built-in Date
|
5
|
+
Extends Ruby's built-in Date and Time classes and supports custom holiday definition lists.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
```
|
10
|
+
gem install holidays
|
11
|
+
```
|
10
12
|
|
11
|
-
|
13
|
+
## Tested versions
|
12
14
|
|
13
|
-
This gem is tested with the following ruby versions:
|
15
|
+
This gem is tested with the following ruby versions:
|
16
|
+
|
17
|
+
* 2.2.0
|
18
|
+
* 2.3.0,
|
19
|
+
* 2.4.0
|
20
|
+
* 2.5.0
|
21
|
+
* JRuby 9.0.5.0
|
22
|
+
|
23
|
+
## Semver
|
14
24
|
|
15
25
|
This gem follows [semantic versioning](http://semver.org/). The guarantee specifically covers:
|
16
26
|
|
17
|
-
* methods in the
|
18
|
-
* the [core
|
27
|
+
* methods in the top-most `Holidays` namespace e.g. `Holidays.<method>`
|
28
|
+
* the [core extensions](#extending-rubys-date-and-time-classes)
|
19
29
|
|
20
30
|
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!
|
21
31
|
|
@@ -23,159 +33,287 @@ Please note that we consider definition changes to be 'minor' bumps, meaning the
|
|
23
33
|
|
24
34
|
Time zones are ignored. This library assumes that all dates are within the same time zone.
|
25
35
|
|
26
|
-
|
36
|
+
## Usage
|
27
37
|
|
28
|
-
|
38
|
+
This gem offers multiple ways to check for holidays for a variety of scenarios.
|
29
39
|
|
30
|
-
|
40
|
+
#### Checking a specific date
|
31
41
|
|
32
|
-
|
33
|
-
=> [{:name => 'ANZAC Day',...}]
|
42
|
+
Get all holidays on April 25, 2008 in Australia:
|
34
43
|
|
35
|
-
|
44
|
+
```
|
45
|
+
Holidays.on(Date.civil(2008, 4, 25), :au)
|
46
|
+
=> [{:name => 'ANZAC Day',...}]
|
47
|
+
```
|
36
48
|
|
37
|
-
|
49
|
+
You can check multiple regions in a single call:
|
38
50
|
|
39
|
-
|
40
|
-
|
51
|
+
```
|
52
|
+
Holidays.on(Date.civil(2008, 1, 1), :us, :fr)
|
53
|
+
=> [{:name=>"New Year's Day", :regions=>[:us],...},
|
54
|
+
{:name=>"Jour de l'an", :regions=>[:fr],...}]
|
55
|
+
```
|
41
56
|
|
42
|
-
|
57
|
+
You can leave off 'regions' to get holidays for any region in our [definitions](https://github.com/holidays/definitions):
|
43
58
|
|
44
|
-
|
45
|
-
|
59
|
+
```
|
60
|
+
Holidays.on(Date.civil(2007, 4, 25))
|
61
|
+
=> [{:name=>"ANZAC Day", :regions=>[:au],...},
|
62
|
+
{:name=>"Festa della Liberazione", :regions=>[:it],...},
|
63
|
+
{:name=>"Dia da Liberdade", :regions=>[:pt],...}
|
64
|
+
...
|
65
|
+
]
|
66
|
+
```
|
46
67
|
|
47
|
-
|
48
|
-
=> [{:name => 'Canada Day',...}
|
49
|
-
{:name => 'Independence Day',...}]
|
68
|
+
#### Checking a date range
|
50
69
|
|
51
|
-
Get all
|
70
|
+
Get all holidays during the month of July 2008 in Canada and the US:
|
52
71
|
|
53
|
-
|
54
|
-
|
72
|
+
```
|
73
|
+
from = Date.civil(2008,7,1)
|
74
|
+
to = Date.civil(2008,7,31)
|
55
75
|
|
56
|
-
|
57
|
-
|
58
|
-
|
76
|
+
Holidays.between(from, to, :ca, :us)
|
77
|
+
=> [{:name => 'Canada Day',...}
|
78
|
+
{:name => 'Independence Day',...}]
|
79
|
+
```
|
59
80
|
|
60
|
-
|
81
|
+
#### Check for 'informal' holidays
|
61
82
|
|
62
|
-
|
63
|
-
to = Date.civil(2008,2,15)
|
83
|
+
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'.
|
64
84
|
|
65
|
-
|
66
|
-
=> [{:name => 'Valentine\'s Day',...}]
|
85
|
+
By default this flag is turned off, meaning no informal holidays will be returned.
|
67
86
|
|
68
|
-
|
87
|
+
Get Valentine's Day in the US:
|
88
|
+
|
89
|
+
```
|
90
|
+
Holidays.on(Date.new(2018, 2, 14), :us, :informal)
|
91
|
+
=> [{:name=>"Valentine's Day",...}]
|
92
|
+
```
|
93
|
+
|
94
|
+
Leaving off 'informal' will mean that Valentine's Day is not returned:
|
95
|
+
|
96
|
+
```
|
97
|
+
Holidays.on(Date.new(2018, 2, 14), :us)
|
98
|
+
=> []
|
99
|
+
```
|
100
|
+
|
101
|
+
Get informal holidays during the month of February 2008 for any region:
|
102
|
+
|
103
|
+
```
|
104
|
+
from = Date.civil(2008,2,1)
|
105
|
+
to = Date.civil(2008,2,15)
|
106
|
+
|
107
|
+
Holidays.between(from, to, :informal)
|
108
|
+
=> [{:name => 'Valentine\'s Day',...}]
|
109
|
+
```
|
110
|
+
|
111
|
+
#### Check for 'observed' holidays
|
112
|
+
|
113
|
+
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'.
|
114
|
+
|
115
|
+
By default this flag is turned off, meaning no observed logic will be applied.
|
116
|
+
|
117
|
+
Get holidays that are observed on Monday July 2, 2007 in British Columbia, Canada:
|
118
|
+
|
119
|
+
```
|
120
|
+
Holidays.on(Date.civil(2007, 7, 2), :ca_bc, :observed)
|
121
|
+
=> [{:name => 'Canada Day',...}]
|
122
|
+
```
|
123
|
+
|
124
|
+
Leaving off the 'observed' flag will mean that 'Canada Day' is not returned since it actually falls on Sunday July 1:
|
69
125
|
|
70
|
-
|
71
|
-
|
126
|
+
```
|
127
|
+
Holidays.on(Date.civil(2007, 7, 2), :ca_bc)
|
128
|
+
=> []
|
129
|
+
Holidays.on(Date.civil(2007, 7, 1), :ca_bc)
|
130
|
+
=> [{:name=>"Canada Day", :regions=>[:ca],...}]
|
131
|
+
```
|
72
132
|
|
73
|
-
|
133
|
+
Get all observed US Federal holidays between 2018 and 2019:
|
74
134
|
|
75
|
-
|
76
|
-
|
135
|
+
```
|
136
|
+
from = Date.civil(2018,1,1)
|
137
|
+
to = Date.civil(2019,12,31)
|
77
138
|
|
78
|
-
|
139
|
+
Holidays.between(from, to, :federal_reserve, :observed)
|
140
|
+
=> [{:name => "New Year's Day"....}
|
141
|
+
{:name => "Birthday of Martin Luther King, Jr"....}]
|
142
|
+
```
|
79
143
|
|
80
|
-
|
81
|
-
=> [{:name => "St. Patrick's Day",...}, {:name => "Good Friday",...}, {:name => "Easter Sunday",...}]
|
144
|
+
#### Check whether any holidays occur during work week
|
82
145
|
|
83
|
-
|
146
|
+
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.
|
84
147
|
|
85
|
-
|
148
|
+
Check whether a holiday falls during first week of the year for any region:
|
86
149
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
{:name=>"Canada Day",...},
|
92
|
-
{:name=>"Civic Holiday",...},
|
93
|
-
{:name=>"Labour Day",...},
|
94
|
-
{:name=>"Thanksgiving",...},
|
95
|
-
{:name=>"Remembrance Day",...},
|
96
|
-
{:name=>"Christmas Day",...},
|
97
|
-
{:name=>"Boxing Day",...}]
|
150
|
+
```
|
151
|
+
Holidays.any_holidays_during_work_week?(Date.civil(2016, 1, 1))
|
152
|
+
=> true
|
153
|
+
```
|
98
154
|
|
99
|
-
|
155
|
+
You can also pass in `informal` or `observed`:
|
100
156
|
|
101
|
-
|
157
|
+
```
|
158
|
+
# Returns true since Valentine's Day falls on a Wednesday
|
159
|
+
holidays.any_holidays_during_work_week?(date.civil(2018, 2, 14), :us, :informal)
|
160
|
+
=> true
|
161
|
+
# Returns false if you don't specify informal
|
162
|
+
irb(main):006:0> Holidays.any_holidays_during_work_week?(Date.civil(2018, 2, 14), :us)
|
163
|
+
=> false
|
164
|
+
# Returns true since Veteran's Day is observed on Monday November 12, 2018
|
165
|
+
holidays.any_holidays_during_work_week?(date.civil(2018, 11, 12), :us, :observed)
|
166
|
+
=> true
|
167
|
+
# Returns false if you don't specify observed since the actual holiday is on Sunday November 11th 2018
|
168
|
+
irb(main):005:0> Holidays.any_holidays_during_work_week?(Date.civil(2018, 11, 12), :us)
|
169
|
+
=> false
|
170
|
+
```
|
102
171
|
|
103
|
-
|
172
|
+
#### Find the next holiday(s) that will occur from a specific date
|
104
173
|
|
105
|
-
|
174
|
+
Get the next holidays occurring from February 23, 2016 for the US:
|
106
175
|
|
107
|
-
|
176
|
+
```
|
177
|
+
Holidays.next_holidays(3, [:us, :informal], Date.civil(2016, 2, 23))
|
178
|
+
=> [{:name => "St. Patrick's Day",...}, {:name => "Good Friday",...}, {:name => "Easter Sunday",...}]
|
179
|
+
```
|
108
180
|
|
109
|
-
|
181
|
+
You can specify the number of holidays to return. This method will default to `Date.today` if no date is provided.
|
110
182
|
|
111
|
-
|
112
|
-
=> [{:name => 'Company Founding',...}]
|
183
|
+
#### Find all holidays occuring starting from a specific date to the end of the year
|
113
184
|
|
114
|
-
|
185
|
+
Get all holidays starting from February 23, 2016 to end of year in the US:
|
115
186
|
|
116
|
-
|
187
|
+
```
|
188
|
+
Holidays.year_holidays([:ca_on], Date.civil(2016, 2, 23))
|
189
|
+
=> [{:name=>"Good Friday",...},
|
190
|
+
{name=>"Easter Sunday",...},
|
191
|
+
{:name=>"Victoria Day",...},
|
192
|
+
{:name=>"Canada Day",...},
|
193
|
+
{:name=>"Civic Holiday",...},
|
194
|
+
{:name=>"Labour Day",...},
|
195
|
+
{:name=>"Thanksgiving",...},
|
196
|
+
{:name=>"Remembrance Day",...},
|
197
|
+
{:name=>"Christmas Day",...},
|
198
|
+
{:name=>"Boxing Day",...}]
|
199
|
+
```
|
117
200
|
|
118
|
-
|
201
|
+
This method will default to `Date.today` if no date is provided.
|
119
202
|
|
120
|
-
|
203
|
+
#### Return all available regions
|
204
|
+
|
205
|
+
Return all available regions:
|
206
|
+
|
207
|
+
```
|
208
|
+
Holidays.available_regions
|
209
|
+
=> [:ar, :at, ..., :sg] # this will be a big array
|
210
|
+
```
|
211
|
+
|
212
|
+
## Loading Custom Definitions on the fly
|
213
|
+
|
214
|
+
In addition to the [provided definitions](https://github.com/holidays/definitions) you can load custom definitions file on the fly and use them immediately.
|
215
|
+
|
216
|
+
To load custom 'Company Founding' holiday on June 1st:
|
217
|
+
|
218
|
+
```
|
219
|
+
Holidays.load_custom('/home/user/holiday_definitions/custom_holidays.yaml')
|
220
|
+
Holidays.on(Date.civil(2013, 6, 1), :my_custom_region)
|
221
|
+
=> [{:name => 'Company Founding',...}]
|
222
|
+
```
|
223
|
+
|
224
|
+
Custom definition files must match the [syntax of the existing definition files](https://github.com/holidays/definitions/blob/master/doc/SYNTAX.md).
|
225
|
+
|
226
|
+
Multiple files can be loaded at the same time:
|
227
|
+
|
228
|
+
```
|
229
|
+
Holidays.load_custom('/home/user/holidays/custom_holidays1.yaml', '/home/user/holidays/custom_holidays2.yaml')
|
230
|
+
```
|
231
|
+
|
232
|
+
## Extending Ruby's Date and Time classes
|
233
|
+
|
234
|
+
### Date
|
121
235
|
|
122
236
|
To extend the 'Date' class:
|
123
237
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
238
|
+
```
|
239
|
+
require 'holidays/core_extensions/date'
|
240
|
+
class Date
|
241
|
+
include Holidays::CoreExtensions::Date
|
242
|
+
end
|
243
|
+
```
|
128
244
|
|
129
245
|
Now you can check which holidays occur in Iceland on January 1, 2008:
|
130
246
|
|
131
|
-
|
247
|
+
```
|
248
|
+
d = Date.civil(2008,7,1)
|
132
249
|
|
133
|
-
|
134
|
-
|
250
|
+
d.holidays(:is)
|
251
|
+
=> [{:name => 'Nýársdagur'}...]
|
252
|
+
```
|
135
253
|
|
136
254
|
Or lookup Canada Day in different regions:
|
137
255
|
|
138
|
-
|
256
|
+
```
|
257
|
+
d = Date.civil(2008,7,1)
|
139
258
|
|
140
|
-
|
141
|
-
|
259
|
+
d.holiday?(:ca) # Canada
|
260
|
+
=> true
|
142
261
|
|
143
|
-
|
144
|
-
|
262
|
+
d.holiday?(:ca_bc) # British Columbia, Canada
|
263
|
+
=> true
|
145
264
|
|
146
|
-
|
147
|
-
|
265
|
+
d.holiday?(:fr) # France
|
266
|
+
=> false
|
267
|
+
```
|
148
268
|
|
149
269
|
Or return the new date based on the options:
|
150
270
|
|
151
|
-
|
152
|
-
|
153
|
-
|
271
|
+
```
|
272
|
+
d = Date.civil(2008,7,1)
|
273
|
+
d.change(:year => 2016, :month => 1, :day => 1)
|
274
|
+
=> #<Date: 2016-01-01 ((2457389j,0s,0n),+0s,2299161j)>
|
275
|
+
```
|
154
276
|
|
155
277
|
Or you can calculate the day of the month:
|
156
278
|
|
157
|
-
|
158
|
-
|
279
|
+
```
|
280
|
+
Date.calculate_mday(2015, 4, :first, 2)
|
281
|
+
=> 7
|
282
|
+
```
|
283
|
+
|
284
|
+
### Time
|
285
|
+
|
286
|
+
```
|
287
|
+
require 'holidays/core_extensions/time'
|
288
|
+
class Time
|
289
|
+
include Holidays::CoreExtensions::Time
|
290
|
+
end
|
291
|
+
```
|
159
292
|
|
160
|
-
|
293
|
+
Find end of month for given date:
|
161
294
|
|
162
|
-
|
163
|
-
|
164
|
-
|
295
|
+
```
|
296
|
+
d = Date.civil(2016,8,1)
|
297
|
+
d.end_of_month
|
298
|
+
=> #<Date: 2016-08-31 ((2457632j,0s,0n),+0s,2299161j)>
|
299
|
+
```
|
165
300
|
|
166
|
-
|
301
|
+
## Caching Holiday Lookups
|
167
302
|
|
168
|
-
If you are checking holidays regularly you can cache your results for improved performance. Run this before looking up a holiday (
|
303
|
+
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):
|
169
304
|
|
170
|
-
|
305
|
+
```
|
306
|
+
YEAR = 365 * 24 * 60 * 60
|
307
|
+
Holidays.cache_between(Time.now, Time.now + 2 * YEAR, :ca, :us, :observed)
|
308
|
+
```
|
171
309
|
|
172
310
|
Holidays for the regions specified within the dates specified will be pre-calculated and stored in-memory. Future lookups will be much faster.
|
173
311
|
|
174
|
-
|
312
|
+
## How to contribute
|
175
313
|
|
176
314
|
See our [contribution guidelines](doc/CONTRIBUTING.md) for information on how to help out!
|
177
315
|
|
178
|
-
|
316
|
+
## Credits and code
|
179
317
|
|
180
318
|
* Started by [@alexdunae](http://github.com/alexdunae) 2007-2012
|
181
319
|
* Maintained by [@hahahana](https://github.com/hahahana), 2013
|
data/holidays.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.require_paths = ['lib']
|
18
18
|
gem.licenses = ['MIT']
|
19
19
|
gem.required_ruby_version = '~> 2.2'
|
20
|
-
gem.add_development_dependency 'bundler'
|
21
|
-
gem.add_development_dependency 'rake', '~> 12
|
20
|
+
gem.add_development_dependency 'bundler', '~> 1.16'
|
21
|
+
gem.add_development_dependency 'rake', '~> 12'
|
22
22
|
gem.add_development_dependency 'simplecov', '~> 0.16'
|
23
23
|
gem.add_development_dependency 'test-unit', '~> 3.2'
|
24
24
|
gem.add_development_dependency 'mocha', '~> 1.7'
|
@@ -19,7 +19,7 @@ module Holidays
|
|
19
19
|
{:function => "easter(year)", :function_arguments => [:year], :function_modifier => 60, :name => "Fronleichnam", :regions => [:ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_zg, :ch_fr, :ch_so, :ch_ai, :ch_ag, :ch_ti, :ch_vs, :ch_ne, :ch_ju]},
|
20
20
|
{:function => "ch_vd_lundi_du_jeune_federal(year)", :function_arguments => [:year], :name => "Lundi du Jeûne fédéral", :regions => [:ch_vd]},
|
21
21
|
{:function => "ch_ge_jeune_genevois(year)", :function_arguments => [:year], :name => "Jeûne genevois", :regions => [:ch_ge]}],
|
22
|
-
1 => [{:mday => 1, :name => "Neujahrstag", :regions => [:
|
22
|
+
1 => [{:mday => 1, :name => "Neujahrstag", :regions => [:ch]},
|
23
23
|
{:mday => 2, :name => "Berchtoldstag", :regions => [:ch_zh, :ch_be, :ch_lu, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_sh, :ch_sg, :ch_ag, :ch_tg, :ch_vd, :ch_vs, :ch_ne, :ch_ju]},
|
24
24
|
{:mday => 6, :name => "Dreikönigstag", :regions => [:ch_ur, :ch_sz, :ch_ti]}],
|
25
25
|
3 => [{:mday => 1, :name => "Instauration de la République", :regions => [:ch_ne]},
|
@@ -151,7 +151,7 @@ module Holidays
|
|
151
151
|
{:mday => 6, :name => "Heilige Drei Könige", :regions => [:at]},
|
152
152
|
{:mday => 1, :name => "Jour de l'an", :regions => [:be_fr]},
|
153
153
|
{:mday => 1, :name => "Nieuwjaar", :regions => [:be_nl]},
|
154
|
-
{:mday => 1, :name => "Neujahrstag", :regions => [:
|
154
|
+
{:mday => 1, :name => "Neujahrstag", :regions => [:ch]},
|
155
155
|
{:mday => 2, :name => "Berchtoldstag", :regions => [:ch_zh, :ch_be, :ch_lu, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_sh, :ch_sg, :ch_ag, :ch_tg, :ch_vd, :ch_vs, :ch_ne, :ch_ju]},
|
156
156
|
{:mday => 6, :name => "Dreikönigstag", :regions => [:ch_ur, :ch_sz, :ch_ti]},
|
157
157
|
{:mday => 1, :name => "Den obnovy samostatného českého státu", :regions => [:cz]},
|
data/lib/holidays.rb
CHANGED
@@ -19,13 +19,12 @@ module Holidays
|
|
19
19
|
|
20
20
|
class << self
|
21
21
|
def any_holidays_during_work_week?(date, *options)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
between(start_date, end_date, options).empty?
|
22
|
+
monday = date - (date.wday - 1)
|
23
|
+
friday = date + (5 - date.wday)
|
24
|
+
|
25
|
+
holidays = between(monday, friday, *options)
|
26
|
+
|
27
|
+
holidays && holidays.count > 0
|
29
28
|
end
|
30
29
|
|
31
30
|
def on(date, *options)
|
@@ -48,6 +47,9 @@ module Holidays
|
|
48
47
|
Factory::Finder.between.call(start_date, end_date, options)
|
49
48
|
end
|
50
49
|
|
50
|
+
#FIXME All other methods start with a date and require a date. For the next
|
51
|
+
# major version bump we should take the opportunity to change this
|
52
|
+
# signature to match, e.g. next_holidays(from_date, count, options)
|
51
53
|
def next_holidays(holidays_count, options, from_date = Date.today)
|
52
54
|
raise ArgumentError unless holidays_count
|
53
55
|
raise ArgumentError if options.empty?
|
@@ -61,6 +63,9 @@ module Holidays
|
|
61
63
|
Factory::Finder.next_holiday.call(holidays_count, from_date, options)
|
62
64
|
end
|
63
65
|
|
66
|
+
#FIXME All other methods start with a date and require a date. For the next
|
67
|
+
# major version bump we should take the opportunity to change this
|
68
|
+
# signature to match, e.g. year_holidays(from_date, options)
|
64
69
|
def year_holidays(options, from_date = Date.today)
|
65
70
|
raise ArgumentError if options.empty?
|
66
71
|
raise ArgumentError unless options.is_a?(Array)
|
@@ -4,7 +4,7 @@ module Holidays
|
|
4
4
|
def self.included(base)
|
5
5
|
base.extend ClassMethods
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
module ClassMethods
|
9
9
|
COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
10
10
|
|
@@ -17,7 +17,7 @@ module Holidays
|
|
17
17
|
COMMON_YEAR_DAYS_IN_MONTH[month]
|
18
18
|
end
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -14,15 +14,14 @@ module Holidays
|
|
14
14
|
regions, observed, informal = @options_parser.call(options)
|
15
15
|
dates_driver = @dates_driver_builder.call(start_date, end_date)
|
16
16
|
|
17
|
-
holidays = []
|
18
|
-
|
19
17
|
#FIXME Why are we calling the options_parser to convert the observed/informal
|
20
18
|
# symbols to bool and then...converting them back? O_o
|
21
19
|
opts = gather_options(observed, informal)
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
@definition_search
|
22
|
+
.call(dates_driver, regions, opts)
|
23
|
+
.select { |holiday| holiday[:date].between?(start_date, end_date) }
|
24
|
+
.sort_by { |a| a[:date] }
|
26
25
|
end
|
27
26
|
|
28
27
|
private
|
@@ -35,8 +34,8 @@ module Holidays
|
|
35
34
|
def gather_options(observed, informal)
|
36
35
|
opts = []
|
37
36
|
|
38
|
-
opts << :observed if observed
|
39
|
-
opts << :informal if informal
|
37
|
+
opts << :observed if observed
|
38
|
+
opts << :informal if informal
|
40
39
|
|
41
40
|
opts
|
42
41
|
end
|
@@ -14,7 +14,6 @@ module Holidays
|
|
14
14
|
regions, observed, informal = @options_parser.call(options)
|
15
15
|
|
16
16
|
holidays = []
|
17
|
-
ret_holidays = []
|
18
17
|
opts = gather_options(observed, informal)
|
19
18
|
|
20
19
|
# This could be smarter but I don't have any evidence that just checking for
|
@@ -22,17 +21,18 @@ module Holidays
|
|
22
21
|
# smarter here to check in smaller increments.
|
23
22
|
dates_driver = @dates_driver_builder.call(from_date, from_date >> 12)
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
@definition_search
|
25
|
+
.call(dates_driver, regions, opts)
|
26
|
+
.sort_by { |a| a[:date] }
|
27
|
+
.each do |holiday|
|
28
|
+
if holiday[:date] >= from_date
|
29
|
+
holidays << holiday
|
30
|
+
holidays_count -= 1
|
31
|
+
break if holidays_count == 0
|
32
|
+
end
|
32
33
|
end
|
33
|
-
end
|
34
34
|
|
35
|
-
holidays.
|
35
|
+
holidays.sort_by { |a| a[:date] }
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
@@ -46,8 +46,8 @@ module Holidays
|
|
46
46
|
def gather_options(observed, informal)
|
47
47
|
opts = []
|
48
48
|
|
49
|
-
opts << :observed if observed
|
50
|
-
opts << :informal if informal
|
49
|
+
opts << :observed if observed
|
50
|
+
opts << :informal if informal
|
51
51
|
|
52
52
|
opts
|
53
53
|
end
|
data/lib/holidays/version.rb
CHANGED
data/test/defs/test_defs_ch.rb
CHANGED
@@ -7,6 +7,8 @@ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
|
7
7
|
class ChDefinitionTests < Test::Unit::TestCase # :nodoc:
|
8
8
|
|
9
9
|
def test_ch
|
10
|
+
assert_equal "Neujahrstag", (Holidays.on(Date.civil(2018, 1, 1), [:ch])[0] || {})[:name]
|
11
|
+
|
10
12
|
assert_equal "Bundesfeiertag", (Holidays.on(Date.civil(2012, 8, 1), [:ch])[0] || {})[:name]
|
11
13
|
|
12
14
|
assert_equal "Weihnachten", (Holidays.on(Date.civil(2012, 12, 25), [:ch])[0] || {})[:name]
|
@@ -95,6 +95,8 @@ class EuropeDefinitionTests < Test::Unit::TestCase # :nodoc:
|
|
95
95
|
|
96
96
|
assert_equal "Pinkstermaandag", (Holidays.on(Date.civil(2017, 6, 5), [:be_nl])[0] || {})[:name]
|
97
97
|
|
98
|
+
assert_equal "Neujahrstag", (Holidays.on(Date.civil(2018, 1, 1), [:ch])[0] || {})[:name]
|
99
|
+
|
98
100
|
assert_equal "Bundesfeiertag", (Holidays.on(Date.civil(2012, 8, 1), [:ch])[0] || {})[:name]
|
99
101
|
|
100
102
|
assert_equal "Weihnachten", (Holidays.on(Date.civil(2012, 12, 25), [:ch])[0] || {})[:name]
|
@@ -0,0 +1,90 @@
|
|
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
|
@@ -20,30 +20,6 @@ class HolidaysTests < Test::Unit::TestCase
|
|
20
20
|
assert_equal 0, holidays.length
|
21
21
|
end
|
22
22
|
|
23
|
-
def test_any_holidays_during_work_week
|
24
|
-
## Full weeks:
|
25
|
-
# Try with a Monday
|
26
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,23), :us)
|
27
|
-
# Try with a Wednesday
|
28
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,25), :us)
|
29
|
-
# Try Sunday on a week going into a new month
|
30
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,29), :us)
|
31
|
-
# Try Wednesday on a week going into a new month
|
32
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,2,1), :us)
|
33
|
-
|
34
|
-
## Weeks with holidays:
|
35
|
-
# New Year's 2012 (on Sunday, observed Monday). Test from a Wednesday.
|
36
|
-
assert_equal(false, Holidays.any_holidays_during_work_week?(Date.civil(2012,1,4), :us))
|
37
|
-
# Ignore observed holidays with :no_observed
|
38
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,4), :us, :no_observed)
|
39
|
-
# Labor Day 2012 should be Sept 3
|
40
|
-
assert_equal(false, Holidays.any_holidays_during_work_week?(Date.civil(2012,9,5), :us))
|
41
|
-
# Should be 10 non-full weeks in the year (in the US)
|
42
|
-
weeks_in_2012 = Date.commercial(2013, -1).cweek
|
43
|
-
holidays_in_2012 = weeks_in_2012.times.count { |week| Holidays.any_holidays_during_work_week?(Date.commercial(2012,week+1), :us) == false }
|
44
|
-
assert_equal 9, holidays_in_2012
|
45
|
-
end
|
46
|
-
|
47
23
|
def test_requires_valid_regions
|
48
24
|
assert_raises Holidays::InvalidRegion do
|
49
25
|
Holidays.on(Date.civil(2008,1,1), :xx)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holidays
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.6.
|
4
|
+
version: 6.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dunae
|
@@ -9,36 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-10-
|
12
|
+
date: 2018-10-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '1.16'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '1.16'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '12
|
34
|
+
version: '12'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '12
|
41
|
+
version: '12'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: simplecov
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -348,6 +348,7 @@ files:
|
|
348
348
|
- test/holidays/finder/rules/test_year_range.rb
|
349
349
|
- test/integration/README.md
|
350
350
|
- test/integration/test_all_regions.rb
|
351
|
+
- test/integration/test_any_holidays_during_work_week.rb
|
351
352
|
- test/integration/test_available_regions.rb
|
352
353
|
- test/integration/test_custom_holidays.rb
|
353
354
|
- test/integration/test_custom_informal_holidays.rb
|
@@ -497,6 +498,7 @@ test_files:
|
|
497
498
|
- test/holidays/finder/rules/test_year_range.rb
|
498
499
|
- test/integration/README.md
|
499
500
|
- test/integration/test_all_regions.rb
|
501
|
+
- test/integration/test_any_holidays_during_work_week.rb
|
500
502
|
- test/integration/test_available_regions.rb
|
501
503
|
- test/integration/test_custom_holidays.rb
|
502
504
|
- test/integration/test_custom_informal_holidays.rb
|