holidays 6.4.0 → 8.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitmodules +1 -1
- data/CHANGELOG.md +80 -0
- data/Makefile +17 -4
- data/README.md +236 -101
- data/Rakefile +1 -1
- data/bin/console +0 -0
- data/bin/setup +1 -0
- data/doc/CONTRIBUTING.md +72 -0
- data/{MAINTAINERS.md → doc/MAINTAINERS.md} +5 -6
- data/{REFERENCES → doc/REFERENCES} +0 -0
- data/holidays.gemspec +8 -9
- data/lib/generated_definitions/MANIFEST +12 -4
- data/lib/generated_definitions/REGIONS.rb +2 -2
- data/lib/generated_definitions/ar.rb +30 -11
- data/lib/generated_definitions/at.rb +2 -2
- data/lib/generated_definitions/au.rb +26 -8
- data/lib/generated_definitions/be_fr.rb +2 -2
- data/lib/generated_definitions/be_nl.rb +2 -2
- data/lib/generated_definitions/bg.rb +2 -2
- data/lib/generated_definitions/br.rb +2 -2
- data/lib/generated_definitions/ca.rb +24 -17
- data/lib/generated_definitions/ch.rb +16 -4
- data/lib/generated_definitions/cl.rb +7 -10
- data/lib/generated_definitions/co.rb +121 -0
- data/lib/generated_definitions/cr.rb +2 -2
- data/lib/generated_definitions/cz.rb +2 -2
- data/lib/generated_definitions/de.rb +8 -5
- data/lib/generated_definitions/dk.rb +2 -2
- data/lib/generated_definitions/{ecb_target.rb → ecbtarget.rb} +10 -10
- data/lib/generated_definitions/ee.rb +2 -2
- data/lib/generated_definitions/el.rb +2 -2
- data/lib/generated_definitions/es.rb +8 -5
- data/lib/generated_definitions/europe.rb +114 -29
- data/lib/generated_definitions/federalreserve.rb +35 -0
- data/lib/generated_definitions/{federal_reserve.rb → federalreservebanks.rb} +15 -14
- data/lib/generated_definitions/fedex.rb +2 -2
- data/lib/generated_definitions/fi.rb +2 -2
- data/lib/generated_definitions/fr.rb +2 -2
- data/lib/generated_definitions/gb.rb +15 -8
- data/lib/generated_definitions/ge.rb +2 -2
- data/lib/generated_definitions/hk.rb +2 -2
- data/lib/generated_definitions/hr.rb +10 -8
- data/lib/generated_definitions/hu.rb +4 -3
- data/lib/generated_definitions/ie.rb +2 -2
- data/lib/generated_definitions/is.rb +2 -2
- data/lib/generated_definitions/it.rb +16 -7
- data/lib/generated_definitions/jp.rb +34 -15
- data/lib/generated_definitions/kr.rb +2 -2
- data/lib/generated_definitions/kz.rb +38 -0
- data/lib/generated_definitions/li.rb +2 -2
- data/lib/generated_definitions/lt.rb +2 -2
- data/lib/generated_definitions/lu.rb +4 -2
- data/lib/generated_definitions/lv.rb +55 -0
- data/lib/generated_definitions/ma.rb +2 -2
- data/lib/generated_definitions/mt_en.rb +2 -2
- data/lib/generated_definitions/mt_mt.rb +2 -2
- data/lib/generated_definitions/mx.rb +7 -7
- data/lib/generated_definitions/my.rb +2 -2
- data/lib/generated_definitions/nerc.rb +2 -2
- data/lib/generated_definitions/ng.rb +33 -0
- data/lib/generated_definitions/nl.rb +2 -2
- data/lib/generated_definitions/no.rb +2 -2
- data/lib/generated_definitions/{north_america.rb → northamerica.rb} +33 -26
- data/lib/generated_definitions/nyse.rb +3 -2
- data/lib/generated_definitions/nz.rb +41 -3
- data/lib/generated_definitions/pe.rb +2 -2
- data/lib/generated_definitions/ph.rb +2 -2
- data/lib/generated_definitions/pl.rb +2 -2
- data/lib/generated_definitions/pt.rb +2 -2
- data/lib/generated_definitions/ro.rb +6 -3
- data/lib/generated_definitions/rs_cyrl.rb +3 -3
- data/lib/generated_definitions/rs_la.rb +3 -3
- data/lib/generated_definitions/ru.rb +2 -2
- data/lib/generated_definitions/scandinavia.rb +2 -2
- data/lib/generated_definitions/se.rb +2 -2
- data/lib/generated_definitions/sg.rb +2 -2
- data/lib/generated_definitions/si.rb +4 -3
- data/lib/generated_definitions/sk.rb +2 -2
- data/lib/generated_definitions/southamerica.rb +247 -0
- data/lib/generated_definitions/th.rb +36 -0
- data/lib/generated_definitions/tn.rb +2 -2
- data/lib/generated_definitions/tr.rb +7 -5
- data/lib/generated_definitions/ua.rb +37 -0
- data/lib/generated_definitions/{united_nations.rb → unitednations.rb} +61 -61
- data/lib/generated_definitions/ups.rb +2 -2
- data/lib/generated_definitions/us.rb +9 -9
- data/lib/generated_definitions/ve.rb +2 -2
- data/lib/generated_definitions/vi.rb +2 -2
- data/lib/generated_definitions/za.rb +3 -3
- data/lib/holidays/core_extensions/time.rb +3 -3
- data/lib/holidays/definition/context/generator.rb +23 -70
- data/lib/holidays/definition/context/load.rb +1 -1
- data/lib/holidays/definition/generator/module.rb +54 -0
- data/lib/holidays/definition/generator/regions.rb +7 -2
- data/lib/holidays/definition/parser/custom_method.rb +2 -2
- data/lib/holidays/definition/repository/cache.rb +2 -1
- data/lib/holidays/definition/repository/holidays_by_month.rb +9 -1
- data/lib/holidays/factory/definition.rb +7 -0
- data/lib/holidays/finder/context/between.rb +6 -7
- data/lib/holidays/finder/context/dates_driver_builder.rb +5 -11
- data/lib/holidays/finder/context/next_holiday.rb +12 -12
- data/lib/holidays/finder/context/parse_options.rb +0 -6
- data/lib/holidays/finder/context/search.rb +39 -32
- data/lib/holidays/finder/rules/year_range.rb +30 -54
- data/lib/holidays/version.rb +1 -1
- data/lib/holidays.rb +14 -7
- data/test/coverage_report.rb +23 -7
- data/test/data/test_custom_informal_holidays_defs.yaml +11 -0
- data/test/data/test_custom_year_range_holiday_defs.yaml +6 -10
- data/test/data/test_multiple_regions_with_conflicts_region_1.yaml +38 -0
- data/test/data/test_multiple_regions_with_conflicts_region_2.yaml +38 -0
- data/test/defs/test_defs_ar.rb +30 -6
- data/test/defs/test_defs_at.rb +5 -3
- data/test/defs/test_defs_au.rb +29 -0
- data/test/defs/test_defs_be_fr.rb +10 -0
- data/test/defs/test_defs_be_nl.rb +10 -0
- data/test/defs/test_defs_ca.rb +63 -8
- data/test/defs/test_defs_ch.rb +6 -0
- data/test/defs/test_defs_co.rb +113 -0
- data/test/defs/test_defs_de.rb +7 -1
- data/test/defs/{test_defs_ecb_target.rb → test_defs_ecbtarget.rb} +11 -11
- data/test/defs/test_defs_es.rb +2 -0
- data/test/defs/test_defs_europe.rb +250 -15
- data/test/defs/test_defs_federalreserve.rb +119 -0
- data/test/defs/test_defs_federalreservebanks.rb +251 -0
- data/test/defs/test_defs_gb.rb +42 -0
- data/test/defs/test_defs_hr.rb +6 -6
- data/test/defs/test_defs_hu.rb +12 -4
- data/test/defs/test_defs_it.rb +20 -0
- data/test/defs/test_defs_jp.rb +30 -2
- data/test/defs/test_defs_kz.rb +39 -0
- data/test/defs/test_defs_lu.rb +6 -0
- data/test/defs/test_defs_lv.rb +96 -0
- data/test/defs/test_defs_mx.rb +3 -1
- data/test/defs/test_defs_ng.rb +29 -0
- data/test/defs/{test_defs_north_america.rb → test_defs_northamerica.rb} +77 -20
- data/test/defs/test_defs_nyse.rb +7 -0
- data/test/defs/test_defs_nz.rb +4 -0
- data/test/defs/test_defs_ro.rb +14 -0
- data/test/defs/test_defs_rs_cyrl.rb +1 -1
- data/test/defs/test_defs_rs_la.rb +1 -1
- data/test/defs/test_defs_southamerica.rb +323 -0
- data/test/defs/test_defs_th.rb +33 -0
- data/test/defs/test_defs_tr.rb +7 -0
- data/test/defs/test_defs_ua.rb +41 -0
- data/test/defs/{test_defs_united_nations.rb → test_defs_unitednations.rb} +3 -3
- data/test/defs/test_defs_us.rb +11 -11
- data/test/holidays/core_extensions/test_date.rb +3 -2
- data/test/holidays/definition/context/test_generator.rb +17 -20
- data/test/holidays/definition/context/test_load.rb +3 -3
- data/test/holidays/definition/generator/test_module.rb +268 -0
- data/test/holidays/definition/parser/test_custom_method.rb +4 -4
- data/test/holidays/definition/repository/test_holidays_by_month.rb +121 -1
- data/test/holidays/finder/context/test_parse_options.rb +0 -10
- data/test/holidays/finder/rules/test_year_range.rb +43 -47
- data/test/integration/test_any_holidays_during_work_week.rb +90 -0
- data/test/integration/test_available_regions.rb +1 -1
- data/test/integration/test_custom_informal_holidays.rb +15 -0
- data/test/integration/test_custom_year_range_holidays.rb +0 -7
- data/test/integration/test_holidays.rb +4 -56
- data/test/integration/test_holidays_between.rb +11 -1
- data/test/integration/test_multiple_regions.rb +54 -6
- data/test/integration/test_multiple_regions_with_conflict.rb +29 -0
- data/test/integration/test_nonstandard_regions.rb +25 -0
- metadata +79 -53
- data/CONTRIBUTING.md +0 -51
- data/test/defs/test_defs_federal_reserve.rb +0 -111
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9eb1a9a2387a3734d10203b125345004d0c470ccc2394b82e36f57277a487db0
|
4
|
+
data.tar.gz: 9a77c89d65379366e70b9d6e3eed67080ce5fadb096c11dad1b5edb81dee2e8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5580b2c4ed9f227fc68558382fa2635df1fb234291b7bd554f3675bea59cf81345be20de1cc7fa8babb9cd445cf1d076dde9eebed1947d75a5a956fdf2ae2158
|
7
|
+
data.tar.gz: 210b384735179c141e9c15d0de847449a3e70cd7e468453afd9b038afced110c1ea957b69d48e1196e524a2da3804af1d3502558407f4a9b71e998fb9ae3da64
|
data/.gitmodules
CHANGED
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:
|
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
|
-
|
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
|
-
|
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
|
-
|
3
|
+
Functionality to deal with holidays in Ruby.
|
4
4
|
|
5
|
-
Extends Ruby's built-in Date
|
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
|
-
|
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
|
-
|
22
|
+
## Semver
|
14
23
|
|
15
|
-
|
24
|
+
This gem follows [semantic versioning](http://semver.org/). The guarantee specifically covers:
|
16
25
|
|
17
|
-
|
18
|
-
|
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
|
-
|
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
|
-
|
35
|
+
## Usage
|
29
36
|
|
30
|
-
|
37
|
+
This gem offers multiple ways to check for holidays for a variety of scenarios.
|
31
38
|
|
32
|
-
|
39
|
+
#### Checking a specific date
|
33
40
|
|
34
|
-
|
35
|
-
=> [{:name => 'ANZAC Day',...}]
|
41
|
+
Get all holidays on April 25, 2008 in Australia:
|
36
42
|
|
37
|
-
|
43
|
+
```
|
44
|
+
Holidays.on(Date.civil(2008, 4, 25), :au)
|
45
|
+
=> [{:name => 'ANZAC Day',...}]
|
46
|
+
```
|
38
47
|
|
39
|
-
|
48
|
+
You can check multiple regions in a single call:
|
40
49
|
|
41
|
-
|
42
|
-
|
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
|
-
|
56
|
+
You can leave off 'regions' to get holidays for any region in our [definitions](https://github.com/holidays/definitions):
|
45
57
|
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
=> [{:name => 'Canada Day',...}
|
51
|
-
{:name => 'Independence Day',...}]
|
67
|
+
#### Checking a date range
|
52
68
|
|
53
|
-
Get all
|
69
|
+
Get all holidays during the month of July 2008 in Canada and the US:
|
54
70
|
|
55
|
-
|
56
|
-
|
71
|
+
```
|
72
|
+
from = Date.civil(2008,7,1)
|
73
|
+
to = Date.civil(2008,7,31)
|
57
74
|
|
58
|
-
|
59
|
-
|
60
|
-
|
75
|
+
Holidays.between(from, to, :ca, :us)
|
76
|
+
=> [{:name => 'Canada Day',...}
|
77
|
+
{:name => 'Independence Day',...}]
|
78
|
+
```
|
61
79
|
|
62
|
-
|
80
|
+
#### Check for 'informal' holidays
|
63
81
|
|
64
|
-
|
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
|
-
|
68
|
-
=> [{:name => 'Valentine\'s Day',...}]
|
84
|
+
By default this flag is turned off, meaning no informal holidays will be returned.
|
69
85
|
|
70
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
78
|
-
=> true
|
132
|
+
Get all observed US Federal holidays between 2018 and 2019:
|
79
133
|
|
80
|
-
|
134
|
+
```
|
135
|
+
from = Date.civil(2018,1,1)
|
136
|
+
to = Date.civil(2019,12,31)
|
81
137
|
|
82
|
-
|
83
|
-
|
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
|
-
|
143
|
+
#### Check whether any holidays occur during work week
|
86
144
|
|
87
|
-
|
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
|
-
|
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
|
-
|
149
|
+
```
|
150
|
+
Holidays.any_holidays_during_work_week?(Date.civil(2016, 1, 1))
|
151
|
+
=> true
|
152
|
+
```
|
102
153
|
|
103
|
-
|
154
|
+
You can also pass in `informal` or `observed`:
|
104
155
|
|
105
|
-
|
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
|
-
|
171
|
+
#### Find the next holiday(s) that will occur from a specific date
|
108
172
|
|
109
|
-
|
173
|
+
Get the next holidays occurring from February 23, 2016 for the US:
|
110
174
|
|
111
|
-
|
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
|
-
|
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
|
-
|
182
|
+
#### Find all holidays occuring starting from a specific date to the end of the year
|
117
183
|
|
118
|
-
|
184
|
+
Get all holidays starting from February 23, 2016 to end of year in the US:
|
119
185
|
|
120
|
-
|
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
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
246
|
+
```
|
247
|
+
d = Date.civil(2008,7,1)
|
134
248
|
|
135
|
-
|
136
|
-
|
249
|
+
d.holidays(:is)
|
250
|
+
=> [{:name => 'Nýársdagur'}...]
|
251
|
+
```
|
137
252
|
|
138
253
|
Or lookup Canada Day in different regions:
|
139
254
|
|
140
|
-
|
255
|
+
```
|
256
|
+
d = Date.civil(2008,7,1)
|
141
257
|
|
142
|
-
|
143
|
-
|
258
|
+
d.holiday?(:ca) # Canada
|
259
|
+
=> true
|
144
260
|
|
145
|
-
|
146
|
-
|
261
|
+
d.holiday?(:ca_bc) # British Columbia, Canada
|
262
|
+
=> true
|
147
263
|
|
148
|
-
|
149
|
-
|
264
|
+
d.holiday?(:fr) # France
|
265
|
+
=> false
|
266
|
+
```
|
150
267
|
|
151
268
|
Or return the new date based on the options:
|
152
269
|
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
160
|
-
|
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
|
-
|
292
|
+
Find end of month for given date:
|
163
293
|
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
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 (
|
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
|
-
|
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
|
-
|
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
|
-
|
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
data/bin/console
CHANGED
File without changes
|
data/bin/setup
CHANGED
data/doc/CONTRIBUTING.md
ADDED
@@ -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
|