holidays 4.7.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/CHANGELOG.md +9 -0
- data/CONTRIBUTING.md +21 -11
- data/Makefile +9 -6
- data/holidays.gemspec +1 -1
- data/lib/generated_definitions/MANIFEST +1 -0
- data/lib/generated_definitions/REGIONS.rb +1 -1
- data/lib/generated_definitions/hk.rb +112 -0
- data/lib/generated_definitions/kr.rb +4 -4
- data/lib/holidays/errors.rb +1 -0
- data/lib/holidays/finder/context/parse_options.rb +8 -3
- data/lib/holidays/load_all_definitions.rb +0 -11
- data/lib/holidays/version.rb +1 -1
- data/test/defs/test_defs_hk.rb +38 -0
- data/test/defs/test_defs_jp.rb +1 -0
- data/test/defs/test_defs_kr.rb +1 -1
- data/test/holidays/definition/validator/test_region.rb +4 -0
- data/test/holidays/finder/context/test_parse_options.rb +9 -1
- data/test/integration/test_all_regions.rb +4 -4
- data/test/integration/test_custom_holidays.rb +4 -4
- data/test/integration/test_holidays.rb +6 -6
- metadata +6 -60
- data/definitions/README.md +0 -353
- data/definitions/ar.yaml +0 -93
- data/definitions/at.yaml +0 -72
- data/definitions/au.yaml +0 -378
- data/definitions/be_fr.yaml +0 -69
- data/definitions/be_nl.yaml +0 -69
- data/definitions/bg.yaml +0 -127
- data/definitions/br.yaml +0 -77
- data/definitions/ca.yaml +0 -317
- data/definitions/ch.yaml +0 -193
- data/definitions/cl.yaml +0 -94
- data/definitions/cr.yaml +0 -65
- data/definitions/cz.yaml +0 -73
- data/definitions/de.yaml +0 -209
- data/definitions/dk.yaml +0 -130
- data/definitions/ecb_target.yaml +0 -44
- data/definitions/el.yaml +0 -84
- data/definitions/es.yaml +0 -203
- data/definitions/federal_reserve.yaml +0 -114
- data/definitions/fedex.yaml +0 -62
- data/definitions/fi.yaml +0 -115
- data/definitions/fr.yaml +0 -79
- data/definitions/gb.yaml +0 -151
- data/definitions/hr.yaml +0 -79
- data/definitions/hu.yaml +0 -63
- data/definitions/ie.yaml +0 -89
- data/definitions/index.yaml +0 -61
- data/definitions/is.yaml +0 -146
- data/definitions/it.yaml +0 -67
- data/definitions/jp.yaml +0 -321
- data/definitions/kr.yaml +0 -282
- data/definitions/li.yaml +0 -107
- data/definitions/lt.yaml +0 -89
- data/definitions/lu.yaml +0 -56
- data/definitions/ma.yaml +0 -52
- data/definitions/mx.yaml +0 -106
- data/definitions/my.yaml +0 -51
- data/definitions/nerc.yaml +0 -51
- data/definitions/nl.yaml +0 -73
- data/definitions/no.yaml +0 -90
- data/definitions/north_america_informal.yaml +0 -61
- data/definitions/nyse.yaml +0 -64
- data/definitions/nz.yaml +0 -163
- data/definitions/pe.yaml +0 -119
- data/definitions/ph.yaml +0 -94
- data/definitions/pl.yaml +0 -320
- data/definitions/pt.yaml +0 -89
- data/definitions/ro.yaml +0 -78
- data/definitions/se.yaml +0 -120
- data/definitions/sg.yaml +0 -56
- data/definitions/si.yaml +0 -86
- data/definitions/sk.yaml +0 -80
- data/definitions/united_nations.yaml +0 -189
- data/definitions/ups.yaml +0 -62
- data/definitions/us.yaml +0 -103
- data/definitions/ve.yaml +0 -74
- data/definitions/vi.yaml +0 -29
- data/definitions/za.yaml +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7ac864cf9a702e79f70f0781f4a9f0739a7909c
|
4
|
+
data.tar.gz: b2f694914ebcf0cd36a7e5b531fd3cc3a9aec3b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2478e61ae75f0d08de0b50c1d7f7a8ec214efc2a919fae11f86866a1fa8c9834b322cef0728fa754fffa32470282ebec807fbe97844e6cb3f911bbb50db3792a
|
7
|
+
data.tar.gz: 01d5ff2c9345147b92c6f13fa7c009f52dfb7939f9c133da9ba36878c6164c957e1ddea81a56a9b31eeaf4cf0bf4cbb0b4199274a9b6027fcade5551a6b941e0
|
data/.gitmodules
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Ruby Holidays Gem CHANGELOG
|
2
2
|
|
3
|
+
## 5.0.0
|
4
|
+
|
5
|
+
* Remove support for jruby 1.7 (this is the main reason for the major semver bump)
|
6
|
+
* Remove support for ruby 2.0 (since it is no longer being supported by the core ruby team)
|
7
|
+
* Add back the lazy loading of regions (this was removed in the 4.0.0 bump) instead of loading upon require (this should have
|
8
|
+
no outward repercussions for users)
|
9
|
+
* Move definitions into their own repository and add as submodule. This will allow for more flexibility for tools written
|
10
|
+
in other languages.
|
11
|
+
|
3
12
|
## 4.7.0
|
4
13
|
|
5
14
|
* Fix issue-225 (`LocalJumpError` for certain `jp` definition combinations) (https://github.com/ttwo32)
|
data/CONTRIBUTING.md
CHANGED
@@ -6,25 +6,34 @@ There are multiple ways to help! We rely on users around the world to help keep
|
|
6
6
|
|
7
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
8
|
|
9
|
+
## General note
|
10
|
+
|
11
|
+
The definitions for this project are housed in a submodule. 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 down.
|
13
|
+
|
9
14
|
## For definition updates
|
10
15
|
|
11
|
-
Our definitions are written in YAML.
|
16
|
+
Our definitions are written in YAML. They are housed in a [separate repository](https://github.com/holidays/definitions) so
|
17
|
+
that they can be used by tools written in other languages. You can find a complete guide to our format in the
|
18
|
+
[definitions SYNTAX guide](https://github.com/holidays/definitions/SYNTAX.md).
|
19
|
+
|
20
|
+
In this ruby project we take the YAML definitions and generate final ruby classes that are loaded at runtime for fast
|
21
|
+
calculations.
|
12
22
|
|
13
|
-
|
23
|
+
Once you have a good idea on what you want to change, please see the [contributing guide](https://github.com/holidays/definitions/CONTRIBUTING.md) in the `definitions` repository.
|
14
24
|
|
15
|
-
*
|
16
|
-
|
17
|
-
* Run `make generate` to generate updated final definitions (they will be located under `lib/generated_definitions/` and `test/defs/`)
|
18
|
-
* Run `make test` to ensure your changes did not introduce errors
|
19
|
-
* Open a PR with *all* of these changes. You *MUST* include the generated definition files and tests in your PR. There is no automatic process to generate definitions at this time
|
25
|
+
*NOTICE* - this whole submodule-definitions-thing is brand-new. If you are confused or run into issues please open an issue.
|
26
|
+
The maintainers will respond immediately to help you out. :)
|
20
27
|
|
21
|
-
|
28
|
+
The idea is that if the validation passes on the other repo then you shouldn't have to worry about generating and testing
|
29
|
+
here. We'll see how that goes!
|
22
30
|
|
23
|
-
|
31
|
+
Once that PR is accepted the maintainers of this project will be responsible for generating the updated definitions and
|
32
|
+
releasing a new gem. Don't worry about versioning, we'll take care of it!
|
24
33
|
|
25
34
|
## For non-definition functionality
|
26
35
|
|
27
|
-
* Fork
|
36
|
+
* Fork this repository
|
28
37
|
* Make your changes
|
29
38
|
* Create a PR pointing back to `master`
|
30
39
|
|
@@ -37,5 +46,6 @@ Don't worry about versioning, we'll handle it on our end.
|
|
37
46
|
We have included a few handy tasks to help you troubleshoot and test:
|
38
47
|
|
39
48
|
* `make test` - runs the entire suite
|
40
|
-
* `REGION=<region> make test_region` - runs the tests for just that region
|
49
|
+
* `REGION=<region> make test_region` - runs the tests for just that region
|
41
50
|
* `make console` - launches an IRB session with the 'holidays' gem loaded for quick testing
|
51
|
+
* `make update_defs` - this will run the appropriate git submodule commands to pull the latest definitions
|
data/Makefile
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
default: test
|
2
2
|
|
3
|
-
setup:
|
3
|
+
setup: update_defs
|
4
4
|
bundle install
|
5
5
|
|
6
|
+
generate: update_defs
|
7
|
+
bundle exec rake generate
|
8
|
+
|
6
9
|
test:
|
7
10
|
bundle exec rake test
|
8
11
|
|
9
|
-
generate:
|
10
|
-
bundle exec rake generate
|
11
|
-
|
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
|
-
build:
|
18
|
+
build: clean
|
19
19
|
bundle exec gem build holidays.gemspec
|
20
20
|
|
21
21
|
push:
|
22
|
-
bundle exec gem push
|
22
|
+
bundle exec gem push $(GEM)
|
23
|
+
|
24
|
+
update_defs:
|
25
|
+
git submodule update --init --remote --recursive
|
23
26
|
|
24
27
|
clean:
|
25
28
|
rm -rf holidays-*.gem
|
data/holidays.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.test_files = gem.files.grep(/^test/)
|
17
17
|
gem.require_paths = ['lib']
|
18
18
|
gem.licenses = ['MIT']
|
19
|
-
gem.required_ruby_version = '~> 2.
|
19
|
+
gem.required_ruby_version = '~> 2.1'
|
20
20
|
gem.add_development_dependency 'bundler'
|
21
21
|
gem.add_development_dependency 'rake'
|
22
22
|
gem.add_development_dependency 'coveralls'
|
@@ -26,6 +26,7 @@ The following definition files are included in this installation:
|
|
26
26
|
* generated_definitions/fi
|
27
27
|
* generated_definitions/fr
|
28
28
|
* generated_definitions/gb
|
29
|
+
* generated_definitions/hk
|
29
30
|
* generated_definitions/hr
|
30
31
|
* generated_definitions/hu
|
31
32
|
* generated_definitions/ie
|
@@ -1,4 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Holidays
|
3
|
-
REGIONS = [:ar, :at, :au, :au_nsw, :au_vic, :au_qld, :au_nt, :au_act, :au_sa, :au_tas_south, :au_wa, :au_tas, :au_qld_cairns, :au_qld_brisbane, :au_tas_north, :au_vic_melbourne, :be_fr, :be_nl, :br, :bg_en, :bg_bg, :ca, :ca_qc, :ca_ab, :ca_sk, :ca_on, :ca_bc, :ca_mb, :ca_ns, :ca_pe, :ca_nf, :ca_nt, :ca_nu, :ca_nb, :ca_yk, :us, :ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_ne, :ch_ge, :ch_ju, :ch_vs, :ch, :cl, :cr, :cz, :dk, :de, :de_bw, :de_by, :de_he, :de_nw, :de_rp, :de_sl, :de_sn_aux, :de_th_aux, :de_sn, :de_st, :de_by_aux, :de_bb, :de_mv, :de_th, :ecb_target, :el, :es_pv, :es_na, :es_an, :es_ib, :es_cm, :es_mu, :es_m, :es_ar, :es_cl, :es_cn, :es_lo, :es_ga, :es_ce, :es_o, :es_ex, :es, :es_ct, :es_v, :es_vc, :federal_reserve, :fedex, :fi, :fr, :gb, :gb_eng, :gb_wls, :gb_eaw, :gb_nir, :gb_sct, :gb_con, :je, :gb_jsy, :gg, :gb_gsy, :im, :gb_iom, :hr, :hu, :ie, :is, :it, :kr, :li, :lt, :ma, :mx, :mx_pue, :us, :ca, :nerc, :nl, :lu, :no, :nyse, :nz, :nz_sl, :nz_we, :nz_ak, :nz_nl, :nz_ne, :nz_ot, :nz_ta, :nz_sc, :nz_hb, :nz_mb, :nz_ca, :nz_ch, :nz_wl, :pe, :ph, :pl, :pt, :ro, :se, :us, :us_dc, :us_ca, :ca, :united_nations, :ups, :za, :ca, :ca_qc, :ca_ab, :ca_sk, :ca_on, :ca_bc, :ca_mb, :ca_ns, :ca_pe, :ca_nf, :ca_nt, :ca_nu, :ca_nb, :ca_yk, :mx, :mx_pue, :us, :us_dc, :us_ca, :dk, :is, :no, :se, :fi, :at, :be_fr, :be_nl, :ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_ne, :ch_ge, :ch_ju, :ch_vs, :ch, :cz, :dk, :de, :de_bw, :de_by, :de_he, :de_nw, :de_rp, :de_sl, :de_sn_aux, :de_th_aux, :de_sn, :de_st, :de_by_aux, :de_bb, :de_mv, :de_th, :el, :es_pv, :es_na, :es_an, :es_ib, :es_cm, :es_mu, :es_m, :es_ar, :es_cl, :es_cn, :es_lo, :es_ga, :es_ce, :es_o, :es_ex, :es, :es_ct, :es_v, :es_vc, :fr, :gb, :gb_eng, :gb_wls, :gb_eaw, :gb_nir, :gb_sct, :gb_con, :je, :gb_jsy, :gg, :gb_gsy, :im, :gb_iom, :hr, :hu, :ie, :is, :it, :li, :lt, :nl, :no, :pl, :pt, :ro, :sk, :si, :bg_en, :bg_bg, :jp, :ve, :vi, :sk, :si, :sg, :my]
|
3
|
+
REGIONS = [:ar, :at, :au, :au_nsw, :au_vic, :au_qld, :au_nt, :au_act, :au_sa, :au_tas_south, :au_wa, :au_tas, :au_qld_cairns, :au_qld_brisbane, :au_tas_north, :au_vic_melbourne, :be_fr, :be_nl, :br, :bg_en, :bg_bg, :ca, :ca_qc, :ca_ab, :ca_sk, :ca_on, :ca_bc, :ca_mb, :ca_ns, :ca_pe, :ca_nf, :ca_nt, :ca_nu, :ca_nb, :ca_yk, :us, :ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_ne, :ch_ge, :ch_ju, :ch_vs, :ch, :cl, :cr, :cz, :dk, :de, :de_bw, :de_by, :de_he, :de_nw, :de_rp, :de_sl, :de_sn_aux, :de_th_aux, :de_sn, :de_st, :de_by_aux, :de_bb, :de_mv, :de_th, :ecb_target, :el, :es_pv, :es_na, :es_an, :es_ib, :es_cm, :es_mu, :es_m, :es_ar, :es_cl, :es_cn, :es_lo, :es_ga, :es_ce, :es_o, :es_ex, :es, :es_ct, :es_v, :es_vc, :federal_reserve, :fedex, :fi, :fr, :gb, :gb_eng, :gb_wls, :gb_eaw, :gb_nir, :gb_sct, :gb_con, :je, :gb_jsy, :gg, :gb_gsy, :im, :gb_iom, :hr, :hk, :hu, :ie, :is, :it, :kr, :li, :lt, :ma, :mx, :mx_pue, :us, :ca, :nerc, :nl, :lu, :no, :nyse, :nz, :nz_sl, :nz_we, :nz_ak, :nz_nl, :nz_ne, :nz_ot, :nz_ta, :nz_sc, :nz_hb, :nz_mb, :nz_ca, :nz_ch, :nz_wl, :pe, :ph, :pl, :pt, :ro, :se, :us, :us_dc, :us_ca, :ca, :united_nations, :ups, :za, :ca, :ca_qc, :ca_ab, :ca_sk, :ca_on, :ca_bc, :ca_mb, :ca_ns, :ca_pe, :ca_nf, :ca_nt, :ca_nu, :ca_nb, :ca_yk, :mx, :mx_pue, :us, :us_dc, :us_ca, :dk, :is, :no, :se, :fi, :at, :be_fr, :be_nl, :ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_ne, :ch_ge, :ch_ju, :ch_vs, :ch, :cz, :dk, :de, :de_bw, :de_by, :de_he, :de_nw, :de_rp, :de_sl, :de_sn_aux, :de_th_aux, :de_sn, :de_st, :de_by_aux, :de_bb, :de_mv, :de_th, :el, :es_pv, :es_na, :es_an, :es_ib, :es_cm, :es_mu, :es_m, :es_ar, :es_cl, :es_cn, :es_lo, :es_ga, :es_ce, :es_o, :es_ex, :es, :es_ct, :es_v, :es_vc, :fr, :gb, :gb_eng, :gb_wls, :gb_eaw, :gb_nir, :gb_sct, :gb_con, :je, :gb_jsy, :gg, :gb_gsy, :im, :gb_iom, :hr, :hu, :ie, :is, :it, :li, :lt, :nl, :no, :pl, :pt, :ro, :sk, :si, :bg_en, :bg_bg, :jp, :ve, :vi, :sk, :si, :sg, :my]
|
4
4
|
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Holidays
|
3
|
+
# This file is generated by the Ruby Holidays gem.
|
4
|
+
#
|
5
|
+
# Definitions loaded: definitions/hk.yaml
|
6
|
+
#
|
7
|
+
# To use the definitions in this file, load it right after you load the
|
8
|
+
# Holiday gem:
|
9
|
+
#
|
10
|
+
# require 'holidays'
|
11
|
+
# require 'generated_definitions/hk'
|
12
|
+
#
|
13
|
+
# All the definitions are available at https://github.com/holidays/holidays
|
14
|
+
module HK # :nodoc:
|
15
|
+
def self.defined_regions
|
16
|
+
[:hk]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.holidays_by_month
|
20
|
+
{
|
21
|
+
0 => [{:function => "cn_new_lunar_day(year)", :function_arguments => [:year], :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Lunar New Year's Day", :regions => [:hk]},
|
22
|
+
{:function => "cn_new_lunar_day(year)", :function_arguments => [:year], :function_modifier => 1, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "The second day of Lunar New Year", :regions => [:hk]},
|
23
|
+
{:function => "cn_new_lunar_day(year)", :function_arguments => [:year], :function_modifier => 2, :observed => "to_weekday_if_boxing_weekend(date)", :observed_arguments => [:date], :name => "The third day of Lunar New Year", :regions => [:hk]},
|
24
|
+
{:function => "easter(year)", :function_arguments => [:year], :function_modifier => -2, :name => "Good Friday", :regions => [:hk]},
|
25
|
+
{:function => "easter(year)", :function_arguments => [:year], :function_modifier => -1, :name => "The day following Good Friday", :regions => [:hk]},
|
26
|
+
{:function => "easter(year)", :function_arguments => [:year], :function_modifier => 1, :name => "Easter Monday", :regions => [:hk]}],
|
27
|
+
1 => [{:mday => 1, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "New Year's Day", :regions => [:hk]}],
|
28
|
+
5 => [{:mday => 1, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Labour Day", :regions => [:hk]}],
|
29
|
+
7 => [{:mday => 1, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "Hong Kong Special Administrative Region Establishment Day", :regions => [:hk]}],
|
30
|
+
10 => [{:mday => 1, :observed => "to_monday_if_sunday(date)", :observed_arguments => [:date], :name => "National Day", :regions => [:hk]}],
|
31
|
+
12 => [{:mday => 25, :observed => "to_monday_if_weekend(date)", :observed_arguments => [:date], :name => "Christmas Day", :regions => [:hk]},
|
32
|
+
{:mday => 26, :observed => "to_weekday_if_boxing_weekend(date)", :observed_arguments => [:date], :name => "Boxing Day", :regions => [:hk]}]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.custom_methods
|
37
|
+
{
|
38
|
+
"cn_new_lunar_day(year)" => Proc.new { |year|
|
39
|
+
month_day = case year
|
40
|
+
when 1930, 1949, 1987, 2025, 2063, 2082, 2101, 2112, 2131, 2150, 2207, 2245, 2253, 2283, 2321
|
41
|
+
[1, 29]
|
42
|
+
when 1931, 1950, 1969, 1988, 2007, 2026, 2045, 2083, 2091, 2102, 2121, 2159, 2197, 2208, 2216, 2227, 2246, 2265, 2303, 2322, 2341, 2379
|
43
|
+
[2, 17]
|
44
|
+
when 1932, 1951, 1970, 1989, 2027, 2046, 2114, 2179, 2198, 2209, 2247, 2266, 2304, 2323, 2342, 2361, 2399
|
45
|
+
[2, 6]
|
46
|
+
when 1933, 2009, 2028, 2047, 2066, 2085, 2115, 2161, 2199, 2210, 2229, 2267, 2305, 2316, 2324, 2335, 2381
|
47
|
+
[1, 26]
|
48
|
+
when 1934, 1953, 2037, 2048, 2067, 2086, 2105, 2116, 2181, 2189, 2211, 2257, 2268, 2306, 2325, 2336
|
49
|
+
[2, 14]
|
50
|
+
when 1935, 1943, 1992, 2038, 2106, 2144, 2201, 2212, 2258, 2296, 2307, 2326, 2364
|
51
|
+
[2, 4]
|
52
|
+
when 1936, 1955, 2001, 2039, 2058, 2088, 2107, 2164, 2183, 2221, 2259, 2278, 2308, 2327, 2373
|
53
|
+
[1, 24]
|
54
|
+
when 1937, 1975, 2032, 2040, 2051, 2070, 2108, 2127, 2146, 2165, 2252, 2260, 2271, 2290, 2309, 2328, 2347, 2366
|
55
|
+
[2, 11]
|
56
|
+
when 1938, 1957, 1976, 1995, 2014, 2033, 2071, 2109, 2128, 2185, 2272, 2291, 2329, 2348, 2367, 2386
|
57
|
+
[1, 31]
|
58
|
+
when 1939, 1996, 2015, 2053, 2072, 2110, 2129, 2292, 2330, 2368, 2387
|
59
|
+
[2, 19]
|
60
|
+
when 1940, 1959, 2016, 2035, 2081, 2130, 2149, 2187, 2206, 2225, 2236, 2255, 2312, 2350, 2358, 2369
|
61
|
+
[2, 8]
|
62
|
+
when 1941, 1952, 1971, 1990, 2074, 2093, 2123, 2142, 2180, 2248, 2294, 2343, 2351, 2362
|
63
|
+
[1, 27]
|
64
|
+
when 1942, 1961, 1972, 1991, 2056, 2075, 2094, 2124, 2143, 2200, 2276, 2295, 2344, 2363
|
65
|
+
[2, 15]
|
66
|
+
when 1944, 1963, 1982, 2020, 2096, 2134, 2153, 2172, 2191, 2202, 2240, 2286, 2354, 2392
|
67
|
+
[1, 25]
|
68
|
+
when 1945, 1964, 1983, 2010, 2029, 2162, 2192, 2230, 2249, 2317, 2382
|
69
|
+
[2, 13]
|
70
|
+
when 1946, 2003, 2022, 2041, 2052, 2098, 2147, 2155, 2166, 2223, 2242, 2261, 2299, 2310, 2375, 2394
|
71
|
+
[2, 1]
|
72
|
+
when 1947, 2004, 2042, 2050, 2080, 2118, 2137, 2194, 2270, 2289, 2300, 2338, 2376
|
73
|
+
[1, 22]
|
74
|
+
when 1948, 1994, 2013, 2024, 2043, 2089, 2119, 2138, 2157, 2176, 2195, 2214, 2320, 2396
|
75
|
+
[2, 10]
|
76
|
+
when 1954, 1973, 2011, 2057, 2068, 2087, 2125, 2163, 2231, 2277, 2288, 2345, 2383
|
77
|
+
[2, 3]
|
78
|
+
when 1956, 2002, 2021, 2059, 2078, 2097, 2135, 2154, 2173, 2184, 2203, 2222, 2241, 2279, 2287, 2298, 2355, 2374, 2393
|
79
|
+
[2, 12]
|
80
|
+
when 1958, 1977, 2034, 2140, 2178, 2235, 2254, 2273, 2311, 2349, 2360, 2398
|
81
|
+
[2, 18]
|
82
|
+
when 1960, 1979, 1998, 2006, 2017, 2036, 2055, 2104, 2169, 2188, 2218, 2226, 2237, 2256, 2275, 2313, 2332, 2370, 2389
|
83
|
+
[1, 28]
|
84
|
+
when 1962, 1981, 2000, 2019, 2065, 2076, 2084, 2095, 2133, 2152, 2171, 2190, 2220, 2239, 2285, 2315, 2334, 2353, 2372, 2391
|
85
|
+
[2, 5]
|
86
|
+
when 1965, 1984, 2030, 2049, 2060, 2079, 2117, 2136, 2174, 2182, 2193, 2204, 2250, 2269, 2280, 2318, 2337, 2356
|
87
|
+
[2, 2]
|
88
|
+
when 1966, 2023, 2061, 2099, 2186, 2262, 2281, 2357, 2395
|
89
|
+
[1, 21]
|
90
|
+
when 1967, 1986, 2005, 2062, 2100, 2168, 2233, 2244, 2263, 2282, 2301, 2339, 2377, 2385, 2388
|
91
|
+
[2, 9]
|
92
|
+
when 1968, 2044, 2090, 2120, 2139, 2158, 2177, 2196, 2215, 2234, 2264, 2302, 2340, 2359, 2378, 2397
|
93
|
+
[1, 30]
|
94
|
+
when 1974, 1993, 2012, 2031, 2069, 2077, 2126, 2145, 2156, 2175, 2213, 2232, 2251, 2297, 2346, 2365, 2384
|
95
|
+
[1, 23]
|
96
|
+
when 1978, 1997, 2008, 2054, 2073, 2092, 2103, 2111, 2122, 2141, 2160, 2217, 2228, 2274, 2293, 2331, 2380
|
97
|
+
[2, 7]
|
98
|
+
when 1980, 1999, 2018, 2064, 2113, 2132, 2151, 2170, 2219, 2238, 2284, 2314, 2333, 2352, 2371, 2390
|
99
|
+
[2, 16]
|
100
|
+
when 1985, 2148, 2167, 2205, 2224, 2243
|
101
|
+
[2, 20]
|
102
|
+
when 2319
|
103
|
+
[2, 21]
|
104
|
+
end
|
105
|
+
Date.civil(year, month_day[0], month_day[1])
|
106
|
+
},
|
107
|
+
|
108
|
+
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -101,7 +101,7 @@ month_day = case year
|
|
101
101
|
[2, 19]
|
102
102
|
when 1920, 1985
|
103
103
|
[2, 20]
|
104
|
-
end
|
104
|
+
end
|
105
105
|
Date.civil(year, month_day[0], month_day[1])
|
106
106
|
},
|
107
107
|
|
@@ -149,7 +149,7 @@ month_day = case year
|
|
149
149
|
[5, 19]
|
150
150
|
when 1934, 1953, 1972, 1983, 2029, 2046, 2048
|
151
151
|
[5, 20]
|
152
|
-
when 1915, 1980, 1991, 2010
|
152
|
+
when 1915, 1980, 1991, 2010
|
153
153
|
[5, 21]
|
154
154
|
when 1904, 1942, 1961, 1999, 2018, 2037
|
155
155
|
[5, 22]
|
@@ -169,7 +169,7 @@ month_day = case year
|
|
169
169
|
[5, 29]
|
170
170
|
when 1906, 2001, 2020
|
171
171
|
[5, 30]
|
172
|
-
end
|
172
|
+
end
|
173
173
|
Date.civil(year, month_day[0], month_day[1])
|
174
174
|
},
|
175
175
|
|
@@ -237,7 +237,7 @@ month_day = case year
|
|
237
237
|
[10, 8]
|
238
238
|
when 2011
|
239
239
|
[10, 9]
|
240
|
-
end
|
240
|
+
end
|
241
241
|
Date.civil(year, month_day[0], month_day[1])
|
242
242
|
},
|
243
243
|
|
data/lib/holidays/errors.rb
CHANGED
@@ -54,7 +54,7 @@ module Holidays
|
|
54
54
|
unless region == :any || @regions_repo.exists?(region)
|
55
55
|
begin
|
56
56
|
load_definition_data(region.to_s)
|
57
|
-
rescue NameError => e
|
57
|
+
rescue NameError, LoadError => e
|
58
58
|
# This could be a sub region that does not have any holiday
|
59
59
|
# definitions of its own; try to load the containing region instead.
|
60
60
|
if region.to_s =~ /_/
|
@@ -71,7 +71,7 @@ module Holidays
|
|
71
71
|
|
72
72
|
def validate!(regions)
|
73
73
|
regions.each do |r|
|
74
|
-
raise
|
74
|
+
raise InvalidRegion unless @region_validator.valid?(r)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -84,12 +84,17 @@ module Holidays
|
|
84
84
|
|
85
85
|
begin
|
86
86
|
load_definition_data(prefix)
|
87
|
-
rescue NameError => e
|
87
|
+
rescue NameError, LoadError => e
|
88
88
|
raise UnknownRegionError.new(e), "Could not load region prefix: #{prefix.to_s}, original subregion: #{sub_reg.to_s}"
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
def load_definition_data(region)
|
93
|
+
# Lazy loading of definition files. We verify the region doesn't
|
94
|
+
# contain malicious stuff in the initial validation.
|
95
|
+
region_definition_file = "#{DEFINITIONS_PATH}/#{region}"
|
96
|
+
require region_definition_file
|
97
|
+
|
93
98
|
target_region_module = Module.const_get("Holidays").const_get(region.upcase)
|
94
99
|
|
95
100
|
@definition_merger.call(
|
@@ -2,17 +2,6 @@ module Holidays
|
|
2
2
|
class LoadAllDefinitions
|
3
3
|
class << self
|
4
4
|
def call
|
5
|
-
path = File.expand_path(File.dirname(__FILE__)) + "/../#{Holidays::DEFINITIONS_PATH}/"
|
6
|
-
|
7
|
-
Dir.foreach(path) do |item|
|
8
|
-
next if item == '.' or item == '..'
|
9
|
-
|
10
|
-
target = path+item
|
11
|
-
next if File.extname(target) != '.rb'
|
12
|
-
|
13
|
-
require target
|
14
|
-
end
|
15
|
-
|
16
5
|
#FIXME I need a better way to do this. I'm thinking of putting these 'common' methods
|
17
6
|
# into some kind of definition file so it can be loaded automatically but I'm afraid
|
18
7
|
# of making that big of a breaking API change since these are public. For the time
|
data/lib/holidays/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
3
|
+
|
4
|
+
# This file is generated by the Ruby Holiday gem.
|
5
|
+
#
|
6
|
+
# Definitions loaded: definitions/hk.yaml
|
7
|
+
class HkDefinitionTests < Test::Unit::TestCase # :nodoc:
|
8
|
+
|
9
|
+
def test_hk
|
10
|
+
{Date.civil(2016,1,1) => 'New Year\'s Day',
|
11
|
+
Date.civil(2016,2,8) => 'Lunar New Year\'s Day',
|
12
|
+
Date.civil(2016,2,9) => 'The second day of Lunar New Year',
|
13
|
+
Date.civil(2016,2,10) => 'The third day of Lunar New Year',
|
14
|
+
Date.civil(2016,3,25) => 'Good Friday',
|
15
|
+
Date.civil(2016,3,26) => 'The day following Good Friday',
|
16
|
+
Date.civil(2016,3,28) => 'Easter Monday',
|
17
|
+
Date.civil(2016,5,2) => 'Labour Day',
|
18
|
+
Date.civil(2016,7,1) => 'Hong Kong Special Administrative Region Establishment Day',
|
19
|
+
Date.civil(2016,10,1) => 'National Day',
|
20
|
+
Date.civil(2016,12,26) => 'Christmas Day',
|
21
|
+
Date.civil(2016,12,27) => 'Boxing Day',
|
22
|
+
Date.civil(2017,1,2) => 'New Year\'s Day',
|
23
|
+
Date.civil(2017,1,28) => 'Lunar New Year\'s Day',
|
24
|
+
Date.civil(2017,1,30) => 'The second day of Lunar New Year',
|
25
|
+
Date.civil(2017,1,31) => 'The third day of Lunar New Year',
|
26
|
+
Date.civil(2017,4,14) => 'Good Friday',
|
27
|
+
Date.civil(2017,4,15) => 'The day following Good Friday',
|
28
|
+
Date.civil(2017,4,17) => 'Easter Monday',
|
29
|
+
Date.civil(2017,5,1) => 'Labour Day',
|
30
|
+
Date.civil(2017,7,1) => 'Hong Kong Special Administrative Region Establishment Day',
|
31
|
+
Date.civil(2017,10,2) => 'National Day',
|
32
|
+
Date.civil(2017,12,25) => 'Christmas Day',
|
33
|
+
Date.civil(2017,12,26) => 'Boxing Day'}.each do |date, name|
|
34
|
+
assert_equal name, (Holidays.on(date, :hk, :observed)[0] || {})[:name]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/test/defs/test_defs_jp.rb
CHANGED
@@ -73,5 +73,6 @@ assert_nil Holidays.on(Date.civil(2015,8,11), :jp)[0]
|
|
73
73
|
# [note] citizens holiday requires that jp_national_culture_day is wednesday.
|
74
74
|
# Before 2003, the closest past year that mathches above condition is 1998.
|
75
75
|
assert_nil Holidays.on(Date.civil(1998,9,22), :jp)[0]
|
76
|
+
|
76
77
|
end
|
77
78
|
end
|
data/test/defs/test_defs_kr.rb
CHANGED
@@ -10,7 +10,7 @@ class KrDefinitionTests < Test::Unit::TestCase # :nodoc:
|
|
10
10
|
{Date.civil(2016,2,8) => "Korean New Year",
|
11
11
|
Date.civil(2016,5,14) => "Buddah\'s Birthday",
|
12
12
|
Date.civil(2016,9,12) => "Korean Thanksgiving",
|
13
|
-
Date.civil(2016,1,1) => "New Year\'s Day",
|
13
|
+
Date.civil(2016,1,1) => "New Year\'s Day",
|
14
14
|
Date.civil(2016,3,1) => "Independence Movement Day",
|
15
15
|
Date.civil(2016,5,5) => "Children\'s Day",
|
16
16
|
Date.civil(2016,6,6) => "Memorial Day",
|
@@ -47,4 +47,8 @@ class RegionValidatorTests < Test::Unit::TestCase
|
|
47
47
|
def test_returns_false_if_wildcard_region_is_invalid
|
48
48
|
assert_equal(false, @subject.valid?(:somethingweird_))
|
49
49
|
end
|
50
|
+
|
51
|
+
def test_returns_false_if_malicious_region_is_given
|
52
|
+
assert_equal(false, @subject.valid?(:"../../../test"))
|
53
|
+
end
|
50
54
|
end
|
@@ -67,8 +67,16 @@ class ParseOptionsTests < Test::Unit::TestCase
|
|
67
67
|
def test_raises_error_if_regions_are_invalid
|
68
68
|
@region_validator.stubs(:valid?).returns(false)
|
69
69
|
|
70
|
-
assert_raise Holidays::
|
70
|
+
assert_raise Holidays::InvalidRegion do
|
71
71
|
@subject.call([:unknown_region])
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
def test_raises_error_if_regions_contain_malicious_directory_changes
|
76
|
+
@region_validator.stubs(:valid?).returns(false)
|
77
|
+
|
78
|
+
assert_raise Holidays::InvalidRegion do
|
79
|
+
@subject.call(["../../test"])
|
80
|
+
end
|
81
|
+
end
|
74
82
|
end
|