holidays 3.3.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -0
  3. data/CONTRIBUTING.md +37 -0
  4. data/README.md +16 -25
  5. data/REFERENCES +4 -1
  6. data/Rakefile +38 -8
  7. data/benchmark.rb +8 -0
  8. data/definitions/README.md +187 -8
  9. data/definitions/ar.yaml +2 -1
  10. data/definitions/at.yaml +17 -13
  11. data/definitions/au.yaml +65 -60
  12. data/definitions/be_fr.yaml +14 -10
  13. data/definitions/be_nl.yaml +8 -4
  14. data/definitions/bg.yaml +12 -6
  15. data/definitions/br.yaml +6 -3
  16. data/definitions/ca.yaml +8 -6
  17. data/definitions/ch.yaml +21 -15
  18. data/definitions/cl.yaml +4 -2
  19. data/definitions/cr.yaml +5 -3
  20. data/definitions/cz.yaml +4 -2
  21. data/definitions/de.yaml +25 -14
  22. data/definitions/dk.yaml +26 -17
  23. data/definitions/ecb_target.yaml +4 -2
  24. data/definitions/el.yaml +23 -18
  25. data/definitions/es.yaml +31 -28
  26. data/definitions/federal_reserve.yaml +12 -12
  27. data/definitions/fedex.yaml +6 -6
  28. data/definitions/fi.yaml +26 -25
  29. data/definitions/fr.yaml +8 -4
  30. data/definitions/gb.yaml +9 -7
  31. data/definitions/hr.yaml +8 -6
  32. data/definitions/hu.yaml +8 -6
  33. data/definitions/ie.yaml +17 -16
  34. data/definitions/index.yaml +1 -1
  35. data/definitions/is.yaml +29 -19
  36. data/definitions/it.yaml +10 -9
  37. data/definitions/jp.yaml +92 -44
  38. data/definitions/li.yaml +25 -20
  39. data/definitions/lt.yaml +2 -1
  40. data/definitions/ma.yaml +7 -7
  41. data/definitions/mx.yaml +11 -11
  42. data/definitions/nerc.yaml +6 -6
  43. data/definitions/nl.yaml +22 -18
  44. data/definitions/no.yaml +19 -11
  45. data/definitions/north_america_informal.yaml +6 -6
  46. data/definitions/nyse.yaml +9 -8
  47. data/definitions/nz.yaml +33 -29
  48. data/definitions/ph.yaml +15 -8
  49. data/definitions/pl.yaml +27 -17
  50. data/definitions/pt.yaml +4 -2
  51. data/definitions/ro.yaml +21 -18
  52. data/definitions/se.yaml +24 -18
  53. data/definitions/sg.yaml +10 -9
  54. data/definitions/si.yaml +4 -2
  55. data/definitions/sk.yaml +4 -2
  56. data/definitions/united_nations.yaml +12 -12
  57. data/definitions/ups.yaml +6 -6
  58. data/definitions/us.yaml +12 -11
  59. data/definitions/ve.yaml +8 -4
  60. data/definitions/vi.yaml +6 -6
  61. data/definitions/za.yaml +26 -24
  62. data/holidays.gemspec +3 -1
  63. data/lib/generated_definitions/MANIFEST +1 -1
  64. data/lib/generated_definitions/ar.rb +8 -6
  65. data/lib/generated_definitions/at.rb +11 -9
  66. data/lib/generated_definitions/au.rb +75 -99
  67. data/lib/generated_definitions/be.rb +12 -10
  68. data/lib/generated_definitions/be_fr.rb +12 -10
  69. data/lib/generated_definitions/be_nl.rb +12 -10
  70. data/lib/generated_definitions/bg.rb +14 -13
  71. data/lib/generated_definitions/br.rb +11 -9
  72. data/lib/generated_definitions/ca.rb +20 -20
  73. data/lib/generated_definitions/ch.rb +41 -44
  74. data/lib/generated_definitions/cl.rb +9 -7
  75. data/lib/generated_definitions/cr.rb +9 -7
  76. data/lib/generated_definitions/cz.rb +9 -6
  77. data/lib/generated_definitions/de.rb +25 -25
  78. data/lib/generated_definitions/dk.rb +17 -15
  79. data/lib/generated_definitions/ecb_target.rb +9 -7
  80. data/lib/generated_definitions/el.rb +13 -11
  81. data/lib/generated_definitions/es.rb +35 -33
  82. data/lib/generated_definitions/europe.rb +234 -247
  83. data/lib/generated_definitions/federal_reserve.rb +11 -9
  84. data/lib/generated_definitions/fedex.rb +42 -0
  85. data/lib/generated_definitions/fi.rb +32 -36
  86. data/lib/generated_definitions/fr.rb +12 -10
  87. data/lib/generated_definitions/gb.rb +15 -13
  88. data/lib/generated_definitions/hr.rb +10 -8
  89. data/lib/generated_definitions/hu.rb +9 -7
  90. data/lib/generated_definitions/ie.rb +17 -17
  91. data/lib/generated_definitions/is.rb +26 -26
  92. data/lib/generated_definitions/it.rb +9 -7
  93. data/lib/generated_definitions/jp.rb +112 -89
  94. data/lib/generated_definitions/li.rb +14 -12
  95. data/lib/generated_definitions/lt.rb +9 -7
  96. data/lib/generated_definitions/ma.rb +7 -5
  97. data/lib/generated_definitions/mx.rb +7 -5
  98. data/lib/generated_definitions/nerc.rb +10 -8
  99. data/lib/generated_definitions/nl.rb +15 -13
  100. data/lib/generated_definitions/no.rb +16 -14
  101. data/lib/generated_definitions/north_america.rb +34 -37
  102. data/lib/generated_definitions/nyse.rb +10 -8
  103. data/lib/generated_definitions/nz.rb +40 -40
  104. data/lib/generated_definitions/ph.rb +17 -13
  105. data/lib/generated_definitions/pl.rb +25 -27
  106. data/lib/generated_definitions/pt.rb +10 -8
  107. data/lib/generated_definitions/ro.rb +11 -9
  108. data/lib/generated_definitions/scandinavia.rb +92 -102
  109. data/lib/generated_definitions/se.rb +25 -27
  110. data/lib/generated_definitions/sg.rb +11 -9
  111. data/lib/generated_definitions/si.rb +10 -8
  112. data/lib/generated_definitions/sk.rb +9 -7
  113. data/lib/generated_definitions/united_nations.rb +7 -5
  114. data/lib/generated_definitions/ups.rb +13 -12
  115. data/lib/generated_definitions/us.rb +20 -21
  116. data/lib/generated_definitions/ve.rb +11 -9
  117. data/lib/generated_definitions/vi.rb +7 -5
  118. data/lib/generated_definitions/za.rb +19 -17
  119. data/lib/holidays.rb +20 -83
  120. data/lib/holidays/date_calculator/weekend_modifier.rb +22 -5
  121. data/lib/holidays/definition/context/generator.rb +67 -29
  122. data/lib/holidays/definition/context/merger.rb +8 -8
  123. data/lib/holidays/definition/decorator/custom_method_proc.rb +28 -0
  124. data/lib/holidays/definition/decorator/custom_method_source.rb +30 -0
  125. data/lib/holidays/definition/entity/custom_method.rb +11 -0
  126. data/lib/holidays/definition/parser/custom_method.rb +69 -0
  127. data/lib/holidays/definition/repository/custom_methods.rb +27 -0
  128. data/lib/holidays/definition/repository/holidays_by_month.rb +1 -1
  129. data/lib/holidays/definition/repository/{proc_cache.rb → proc_result_cache.rb} +19 -4
  130. data/lib/holidays/definition/validator/custom_method.rb +31 -0
  131. data/lib/holidays/definition_factory.rb +42 -6
  132. data/lib/holidays/errors.rb +6 -0
  133. data/lib/holidays/load_all_definitions.rb +57 -0
  134. data/lib/holidays/option/context/parse_options.rb +26 -16
  135. data/lib/holidays/option_factory.rb +1 -0
  136. data/lib/holidays/use_case/context/between.rb +41 -14
  137. data/lib/holidays/use_case_factory.rb +2 -1
  138. data/lib/holidays/version.rb +1 -1
  139. data/test/data/test_single_custom_holiday_with_custom_procs.yaml +24 -0
  140. data/test/defs/test_defs_at.rb +1 -1
  141. data/test/defs/test_defs_au.rb +3 -2
  142. data/test/defs/test_defs_cr.rb +1 -0
  143. data/test/defs/test_defs_cz.rb +1 -0
  144. data/test/defs/test_defs_dk.rb +2 -2
  145. data/test/defs/test_defs_el.rb +7 -6
  146. data/test/defs/test_defs_europe.rb +40 -33
  147. data/test/defs/test_defs_fedex.rb +24 -0
  148. data/test/defs/test_defs_fi.rb +4 -3
  149. data/test/defs/test_defs_hr.rb +2 -2
  150. data/test/defs/test_defs_hu.rb +2 -2
  151. data/test/defs/test_defs_is.rb +2 -1
  152. data/test/defs/test_defs_it.rb +2 -1
  153. data/test/defs/test_defs_jp.rb +1 -1
  154. data/test/defs/test_defs_li.rb +1 -1
  155. data/test/defs/test_defs_ma.rb +2 -1
  156. data/test/defs/test_defs_mx.rb +4 -3
  157. data/test/defs/test_defs_nl.rb +7 -6
  158. data/test/defs/test_defs_no.rb +1 -0
  159. data/test/defs/test_defs_north_america.rb +4 -3
  160. data/test/defs/test_defs_nyse.rb +2 -1
  161. data/test/defs/test_defs_pl.rb +1 -0
  162. data/test/defs/test_defs_ro.rb +11 -11
  163. data/test/defs/test_defs_scandinavia.rb +12 -8
  164. data/test/defs/test_defs_se.rb +3 -2
  165. data/test/defs/test_defs_sg.rb +2 -1
  166. data/test/defs/test_defs_vi.rb +1 -1
  167. data/test/defs/test_defs_za.rb +3 -2
  168. data/test/holidays/date_calculator/test_weekend_modifier.rb +11 -0
  169. data/test/holidays/definition/context/test_generator.rb +64 -5
  170. data/test/holidays/definition/context/test_merger.rb +5 -2
  171. data/test/holidays/definition/decorator/test_custom_method_proc.rb +113 -0
  172. data/test/holidays/definition/decorator/test_custom_method_source.rb +96 -0
  173. data/test/holidays/definition/parser/test_custom_method.rb +79 -0
  174. data/test/holidays/definition/repository/test_custom_methods.rb +43 -0
  175. data/test/holidays/definition/repository/test_holidays_by_month.rb +0 -32
  176. data/test/holidays/definition/repository/test_proc_result_cache.rb +84 -0
  177. data/test/holidays/definition/validator/test_custom_method.rb +89 -0
  178. data/test/holidays/option/context/test_parse_options.rb +5 -0
  179. data/test/holidays/test_definition_factory.rb +17 -2
  180. data/test/holidays/use_case/context/test_between.rb +2 -0
  181. data/test/test_all_regions.rb +7 -49
  182. data/test/test_custom_holidays.rb +8 -2
  183. data/test/test_helper.rb +9 -2
  184. data/test/test_holidays.rb +9 -29
  185. metadata +46 -11
  186. data/lib/generated_definitions/fed_ex.rb +0 -41
  187. data/test/holidays/definition/repository/test_proc_cache.rb +0 -29
  188. data/test/test_parse_definitions.rb +0 -30
@@ -27,8 +27,23 @@ class DefinitionFactoryTests < Test::Unit::TestCase
27
27
  assert Holidays::DefinitionFactory.cache_repository.is_a?(Holidays::Definition::Repository::Cache)
28
28
  end
29
29
 
30
- def test_proc_cache_repository
31
- assert Holidays::DefinitionFactory.proc_cache_repository.is_a?(Holidays::Definition::Repository::ProcCache)
30
+ def test_proc_result_cache_repository
31
+ assert Holidays::DefinitionFactory.proc_result_cache_repository.is_a?(Holidays::Definition::Repository::ProcResultCache)
32
32
  end
33
33
 
34
+ def test_custom_method_parser
35
+ assert Holidays::DefinitionFactory.custom_method_parser.is_a?(Holidays::Definition::Parser::CustomMethod)
36
+ end
37
+
38
+ def test_custom_method_source_decorator
39
+ assert Holidays::DefinitionFactory.custom_method_source_decorator.is_a?(Holidays::Definition::Decorator::CustomMethodSource)
40
+ end
41
+
42
+ def test_custom_method_validator
43
+ assert Holidays::DefinitionFactory.custom_method_validator.is_a?(Holidays::Definition::Validator::CustomMethod)
44
+ end
45
+
46
+ def test_region_validator
47
+ assert Holidays::DefinitionFactory.region_validator.is_a?(Holidays::Definition::Validator::Region)
48
+ end
34
49
  end
@@ -9,11 +9,13 @@ class BetweenTests < Test::Unit::TestCase
9
9
  def setup
10
10
  @holidays_by_month_repo = mock()
11
11
  @day_of_month_calculator = mock()
12
+ @custom_method_repo = mock()
12
13
  @proc_cache_repo = mock()
13
14
 
14
15
  @subject = Holidays::UseCase::Context::Between.new(
15
16
  @holidays_by_month_repo,
16
17
  @day_of_month_calculator,
18
+ @custom_method_repo,
17
19
  @proc_cache_repo,
18
20
  )
19
21
 
@@ -1,60 +1,23 @@
1
1
  require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
3
  class MultipleRegionsTests < Test::Unit::TestCase
4
+ def setup
5
+ Holidays::LoadAllDefinitions.call
6
+ end
4
7
 
5
8
  def test_definition_dir
6
9
  assert File.directory?(Holidays::FULL_DEFINITIONS_PATH)
7
10
  end
8
11
 
9
- def test_getting_available_paths
10
- defs = Holidays.available(true)
11
- assert_equal def_count, defs.size
12
+ def test_show_available_regions
13
+ regions = Holidays.available_regions
12
14
 
13
- defs.each do |f|
14
- assert f.kind_of?(String)
15
- assert File.exist?(f)
16
- end
17
- end
18
-
19
- def test_getting_available_symbols
20
- defs = Holidays.available(false)
21
- assert_equal def_count, defs.size
22
-
23
- defs.each { |f| assert f.kind_of?(Symbol) }
24
-
25
- # some spot checks
26
- assert defs.include?(:ca)
27
- assert defs.include?(:united_nations)
28
- end
29
-
30
- def test_loading_all
31
- Holidays.load_all
32
- holidays = Holidays.on(Date.civil(2011, 5, 1), :any)
33
-
34
- # at least 15 now, but there could be more in the future
35
- assert holidays.size > 15
36
-
37
- # some spot checks
38
- assert holidays.any? { |h| h[:name] == 'Staatsfeiertag' } # :at
39
- assert holidays.any? { |h| h[:name] == 'Dia do Trabalho' } # :br
40
- assert holidays.any? { |h| h[:name] == 'Vappu' } # :fi
41
- end
42
-
43
- def test_getting_regions
44
- Holidays.load_all
45
- regions = Holidays.regions
46
-
47
- assert regions.size > 30
48
-
49
- assert regions.include? :nyse
50
- assert regions.include? :united_nations
15
+ assert_equal regions.size, Holidays::REGIONS.size
16
+ assert_equal regions, Holidays::REGIONS
51
17
  end
52
18
 
53
19
  def test_load_subregion
54
- Holidays.send(:remove_const, :DE) #unload de module so that is has to be loaded again
55
- Holidays.send(:class_variable_set, :@@regions, []) # reset regions
56
20
  holidays = Holidays.on(Date.civil(2014, 1, 1), :de_bb)
57
-
58
21
  assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
59
22
  end
60
23
 
@@ -69,9 +32,4 @@ class MultipleRegionsTests < Test::Unit::TestCase
69
32
  Holidays.between(Date.civil(2014, 1, 1), Date.civil(2016, 1, 1), '../../../../../../../../../../../../tmp/profile_pic.jpg')
70
33
  end
71
34
  end
72
-
73
- private
74
- def def_count
75
- Dir.glob(Holidays::FULL_DEFINITIONS_PATH + '/*.rb').size
76
- end
77
35
  end
@@ -7,11 +7,17 @@ class CustomHolidaysTest < Test::Unit::TestCase
7
7
  Holidays.on(Date.civil(2013,6,20), :custom_single_file)
8
8
  end
9
9
 
10
- Holidays.load_custom('test/data/test_single_custom_holiday_defs.yaml')
10
+ loaded_holidays = Holidays.load_custom('test/data/test_single_custom_holiday_defs.yaml')
11
11
 
12
12
  assert_not_equal [], Holidays.on(Date.civil(2013,6,20), :custom_single_file)
13
13
  end
14
14
 
15
+ def test_load_custom_returns_loaded_holidays
16
+ expected_loaded_holidays = {6=>[{:mday=>20, :name=>"Company Founding", :regions=>[:custom_single_file]}]}
17
+
18
+ assert_equal expected_loaded_holidays, Holidays.load_custom('test/data/test_single_custom_holiday_defs.yaml')
19
+ end
20
+
15
21
  def test_custom_holidays_present_after_multiple_file_parsing
16
22
  assert_raises Holidays::UnknownRegionError do
17
23
  Holidays.on(Date.civil(2013, 10,5), :custom_multiple_files)
@@ -32,4 +38,4 @@ class CustomHolidaysTest < Test::Unit::TestCase
32
38
  assert_not_equal [], Holidays.on(Date.civil(2013,3,1), :custom_multiple_files_govt)
33
39
  end
34
40
 
35
- end
41
+ end
@@ -10,7 +10,12 @@ require 'test/unit'
10
10
  require 'mocha/test_unit'
11
11
  require 'date'
12
12
  require 'holidays'
13
- require "#{Holidays::DEFINITIONS_PATH}/ca"
13
+ require 'holidays/core_extensions/date'
14
+
15
+ # Loads core extension for use in various definition tests as necessary
16
+ class Date
17
+ include Holidays::CoreExtensions::Date
18
+ end
14
19
 
15
20
  module Holidays
16
21
  # Test region used for generating a holiday on Date.today
@@ -20,7 +25,9 @@ module Holidays
20
25
  HOLIDAYS_BY_MONTH = {
21
26
  Date.today.mon => [{:mday => Date.today.mday, :name => "Test Holiday", :regions => [:test]}]
22
27
  }
28
+
29
+ CUSTOM_METHODS = {}
23
30
  end
24
31
  end
25
32
 
26
- Holidays.merge_defs(Holidays::Test::DEFINED_REGIONS, Holidays::Test::HOLIDAYS_BY_MONTH)
33
+ Holidays::DefinitionFactory.merger.call(Holidays::Test::DEFINED_REGIONS, Holidays::Test::HOLIDAYS_BY_MONTH, Holidays::Test::CUSTOM_METHODS)
@@ -19,27 +19,27 @@ class HolidaysTests < Test::Unit::TestCase
19
19
  assert_equal 0, holidays.length
20
20
  end
21
21
 
22
- def test_full_week
22
+ def test_any_holidays_during_work_week
23
23
  ## Full weeks:
24
24
  # Try with a Monday
25
- assert Holidays.full_week?(Date.civil(2012,1,23), :us)
25
+ assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,23), :us)
26
26
  # Try with a Wednesday
27
- assert Holidays.full_week?(Date.civil(2012,1,25), :us)
27
+ assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,25), :us)
28
28
  # Try Sunday on a week going into a new month
29
- assert Holidays.full_week?(Date.civil(2012,1,29), :us)
29
+ assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,29), :us)
30
30
  # Try Wednesday on a week going into a new month
31
- assert Holidays.full_week?(Date.civil(2012,2,1), :us)
31
+ assert Holidays.any_holidays_during_work_week?(Date.civil(2012,2,1), :us)
32
32
 
33
33
  ## Weeks with holidays:
34
34
  # New Year's 2012 (on Sunday, observed Monday). Test from a Wednesday.
35
- assert_equal(false, Holidays.full_week?(Date.civil(2012,1,4), :us))
35
+ assert_equal(false, Holidays.any_holidays_during_work_week?(Date.civil(2012,1,4), :us))
36
36
  # Ignore observed holidays with :no_observed
37
- assert Holidays.full_week?(Date.civil(2012,1,4), :us, :no_observed)
37
+ assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,4), :us, :no_observed)
38
38
  # Labor Day 2012 should be Sept 3
39
- assert_equal(false, Holidays.full_week?(Date.civil(2012,9,5), :us))
39
+ assert_equal(false, Holidays.any_holidays_during_work_week?(Date.civil(2012,9,5), :us))
40
40
  # Should be 10 non-full weeks in the year (in the US)
41
41
  weeks_in_2012 = Date.commercial(2013, -1).cweek
42
- holidays_in_2012 = weeks_in_2012.times.count { |week| Holidays.full_week?(Date.commercial(2012,week+1), :us) == false }
42
+ holidays_in_2012 = weeks_in_2012.times.count { |week| Holidays.any_holidays_during_work_week?(Date.commercial(2012,week+1), :us) == false }
43
43
  assert_equal 10, holidays_in_2012
44
44
  end
45
45
 
@@ -104,26 +104,6 @@ class HolidaysTests < Test::Unit::TestCase
104
104
  assert_equal 2, holidays.length
105
105
  end
106
106
 
107
- def test_easter_sunday
108
- assert_equal '1800-04-13', Holidays.easter(1800).to_s
109
- assert_equal '1899-04-02', Holidays.easter(1899).to_s
110
- assert_equal '1900-04-15', Holidays.easter(1900).to_s
111
- assert_equal '1999-04-04', Holidays.easter(1999).to_s
112
- assert_equal '2000-04-23', Holidays.easter(2000).to_s
113
- assert_equal '2025-04-20', Holidays.easter(2025).to_s
114
- assert_equal '2035-03-25', Holidays.easter(2035).to_s
115
- assert_equal '2067-04-03', Holidays.easter(2067).to_s
116
- assert_equal '2099-04-12', Holidays.easter(2099).to_s
117
- end
118
-
119
- def test_orthodox_easter
120
- assert_equal '2000-04-30', Holidays.orthodox_easter(2000).to_s
121
- assert_equal '2008-04-27', Holidays.orthodox_easter(2008).to_s
122
- assert_equal '2009-04-19', Holidays.orthodox_easter(2009).to_s
123
- assert_equal '2011-04-24', Holidays.orthodox_easter(2011).to_s
124
- assert_equal '2020-04-19', Holidays.orthodox_easter(2020).to_s
125
- end
126
-
127
107
  def test_easter_lambda
128
108
  [Date.civil(1800,4,11), Date.civil(1899,3,31), Date.civil(1900,4,13),
129
109
  Date.civil(2008,3,21), Date.civil(2035,3,23)].each do |date|
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: 3.3.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-17 00:00:00.000000000 Z
12
+ date: 2016-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -81,21 +81,36 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '1.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.10'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.10'
84
98
  description: A collection of Ruby methods to deal with statutory and other holidays.
85
99
  You deserve a holiday!
86
100
  email:
87
- - code@dunae.ca
88
101
  - holidaysgem@gmail.com
89
102
  executables: []
90
103
  extensions: []
91
104
  extra_rdoc_files: []
92
105
  files:
93
106
  - CHANGELOG.md
107
+ - CONTRIBUTING.md
94
108
  - Gemfile
95
109
  - LICENSE
96
110
  - README.md
97
111
  - REFERENCES
98
112
  - Rakefile
113
+ - benchmark.rb
99
114
  - bin/console
100
115
  - bin/setup
101
116
  - definitions/README.md
@@ -174,8 +189,8 @@ files:
174
189
  - lib/generated_definitions/el.rb
175
190
  - lib/generated_definitions/es.rb
176
191
  - lib/generated_definitions/europe.rb
177
- - lib/generated_definitions/fed_ex.rb
178
192
  - lib/generated_definitions/federal_reserve.rb
193
+ - lib/generated_definitions/fedex.rb
179
194
  - lib/generated_definitions/fi.rb
180
195
  - lib/generated_definitions/fr.rb
181
196
  - lib/generated_definitions/gb.rb
@@ -218,12 +233,20 @@ files:
218
233
  - lib/holidays/date_calculator_factory.rb
219
234
  - lib/holidays/definition/context/generator.rb
220
235
  - lib/holidays/definition/context/merger.rb
236
+ - lib/holidays/definition/decorator/custom_method_proc.rb
237
+ - lib/holidays/definition/decorator/custom_method_source.rb
238
+ - lib/holidays/definition/entity/custom_method.rb
239
+ - lib/holidays/definition/parser/custom_method.rb
221
240
  - lib/holidays/definition/repository/cache.rb
241
+ - lib/holidays/definition/repository/custom_methods.rb
222
242
  - lib/holidays/definition/repository/holidays_by_month.rb
223
- - lib/holidays/definition/repository/proc_cache.rb
243
+ - lib/holidays/definition/repository/proc_result_cache.rb
224
244
  - lib/holidays/definition/repository/regions.rb
245
+ - lib/holidays/definition/validator/custom_method.rb
225
246
  - lib/holidays/definition/validator/region.rb
226
247
  - lib/holidays/definition_factory.rb
248
+ - lib/holidays/errors.rb
249
+ - lib/holidays/load_all_definitions.rb
227
250
  - lib/holidays/option/context/parse_options.rb
228
251
  - lib/holidays/option_factory.rb
229
252
  - lib/holidays/use_case/context/between.rb
@@ -234,6 +257,7 @@ files:
234
257
  - test/data/test_custom_year_range_holiday_defs.yaml
235
258
  - test/data/test_multiple_custom_holiday_defs.yaml
236
259
  - test/data/test_single_custom_holiday_defs.yaml
260
+ - test/data/test_single_custom_holiday_with_custom_procs.yaml
237
261
  - test/defs/test_defs_ar.rb
238
262
  - test/defs/test_defs_at.rb
239
263
  - test/defs/test_defs_au.rb
@@ -254,6 +278,7 @@ files:
254
278
  - test/defs/test_defs_europe.rb
255
279
  - test/defs/test_defs_fed_ex.rb
256
280
  - test/defs/test_defs_federal_reserve.rb
281
+ - test/defs/test_defs_fedex.rb
257
282
  - test/defs/test_defs_fi.rb
258
283
  - test/defs/test_defs_fr.rb
259
284
  - test/defs/test_defs_gb.rb
@@ -295,10 +320,15 @@ files:
295
320
  - test/holidays/date_calculator/test_weekend_modifier.rb
296
321
  - test/holidays/definition/context/test_generator.rb
297
322
  - test/holidays/definition/context/test_merger.rb
323
+ - test/holidays/definition/decorator/test_custom_method_proc.rb
324
+ - test/holidays/definition/decorator/test_custom_method_source.rb
325
+ - test/holidays/definition/parser/test_custom_method.rb
298
326
  - test/holidays/definition/repository/test_cache.rb
327
+ - test/holidays/definition/repository/test_custom_methods.rb
299
328
  - test/holidays/definition/repository/test_holidays_by_month.rb
300
- - test/holidays/definition/repository/test_proc_cache.rb
329
+ - test/holidays/definition/repository/test_proc_result_cache.rb
301
330
  - test/holidays/definition/repository/test_regions.rb
331
+ - test/holidays/definition/validator/test_custom_method.rb
302
332
  - test/holidays/definition/validator/test_region.rb
303
333
  - test/holidays/option/context/test_parse_options.rb
304
334
  - test/holidays/test_date_calculator_factory.rb
@@ -314,7 +344,6 @@ files:
314
344
  - test/test_holidays.rb
315
345
  - test/test_holidays_between.rb
316
346
  - test/test_multiple_regions.rb
317
- - test/test_parse_definitions.rb
318
347
  homepage: https://github.com/holidays/holidays
319
348
  licenses:
320
349
  - MIT
@@ -325,9 +354,9 @@ require_paths:
325
354
  - lib
326
355
  required_ruby_version: !ruby/object:Gem::Requirement
327
356
  requirements:
328
- - - ">="
357
+ - - "~>"
329
358
  - !ruby/object:Gem::Version
330
- version: '0'
359
+ version: '2.0'
331
360
  required_rubygems_version: !ruby/object:Gem::Requirement
332
361
  requirements:
333
362
  - - ">="
@@ -344,6 +373,7 @@ test_files:
344
373
  - test/data/test_custom_year_range_holiday_defs.yaml
345
374
  - test/data/test_multiple_custom_holiday_defs.yaml
346
375
  - test/data/test_single_custom_holiday_defs.yaml
376
+ - test/data/test_single_custom_holiday_with_custom_procs.yaml
347
377
  - test/defs/test_defs_ar.rb
348
378
  - test/defs/test_defs_at.rb
349
379
  - test/defs/test_defs_au.rb
@@ -364,6 +394,7 @@ test_files:
364
394
  - test/defs/test_defs_europe.rb
365
395
  - test/defs/test_defs_fed_ex.rb
366
396
  - test/defs/test_defs_federal_reserve.rb
397
+ - test/defs/test_defs_fedex.rb
367
398
  - test/defs/test_defs_fi.rb
368
399
  - test/defs/test_defs_fr.rb
369
400
  - test/defs/test_defs_gb.rb
@@ -405,10 +436,15 @@ test_files:
405
436
  - test/holidays/date_calculator/test_weekend_modifier.rb
406
437
  - test/holidays/definition/context/test_generator.rb
407
438
  - test/holidays/definition/context/test_merger.rb
439
+ - test/holidays/definition/decorator/test_custom_method_proc.rb
440
+ - test/holidays/definition/decorator/test_custom_method_source.rb
441
+ - test/holidays/definition/parser/test_custom_method.rb
408
442
  - test/holidays/definition/repository/test_cache.rb
443
+ - test/holidays/definition/repository/test_custom_methods.rb
409
444
  - test/holidays/definition/repository/test_holidays_by_month.rb
410
- - test/holidays/definition/repository/test_proc_cache.rb
445
+ - test/holidays/definition/repository/test_proc_result_cache.rb
411
446
  - test/holidays/definition/repository/test_regions.rb
447
+ - test/holidays/definition/validator/test_custom_method.rb
412
448
  - test/holidays/definition/validator/test_region.rb
413
449
  - test/holidays/option/context/test_parse_options.rb
414
450
  - test/holidays/test_date_calculator_factory.rb
@@ -424,4 +460,3 @@ test_files:
424
460
  - test/test_holidays.rb
425
461
  - test/test_holidays_between.rb
426
462
  - test/test_multiple_regions.rb
427
- - test/test_parse_definitions.rb
@@ -1,41 +0,0 @@
1
- # encoding: utf-8
2
- module Holidays
3
- # This file is generated by the Ruby Holidays gem.
4
- #
5
- # Definitions loaded: definitions/fedex.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/fed_ex'
12
- #
13
- # All the definitions are available at https://github.com/alexdunae/holidays
14
- module FED_EX # :nodoc:
15
- def self.defined_regions
16
- [:fedex]
17
- end
18
-
19
- def self.holidays_by_month
20
- {
21
- 1 => [{:mday => 1, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "New Year's Day", :regions => [:fedex]}],
22
- 5 => [{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:fedex]}],
23
- 7 => [{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Independence Day", :regions => [:fedex]}],
24
- 9 => [{:wday => 1, :week => 1, :name => "Labor Day", :regions => [:fedex]}],
25
- 11 => [{:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:fedex]},
26
- {:function => lambda { |year| Holidays.day_after_thanksgiving(year) }, :function_id => "day_after_thanksgiving(year)", :name => "Day After Thanksgiving", :regions => [:fedex]}],
27
- 12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Christmas Day", :regions => [:fedex]},
28
- {:mday => 31, :name => "New Year's Eve", :regions => [:fedex]}]
29
- }
30
- end
31
- end
32
-
33
- def self.day_after_thanksgiving(year)
34
- Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 11, 4, 4) + 1
35
- end
36
-
37
-
38
-
39
- end
40
-
41
- Holidays.merge_defs(Holidays::FED_EX.defined_regions, Holidays::FED_EX.holidays_by_month)
@@ -1,29 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/definition/repository/proc_cache'
4
-
5
- class ProcCacheRepoTests < Test::Unit::TestCase
6
- def setup
7
- @subject = Holidays::Definition::Repository::ProcCache.new
8
- end
9
-
10
- def test_lookup_stores_and_returns_result_of_function_if_it_is_not_present
11
- function = lambda { |year| Date.civil(year, 2, 1) - 1 }
12
- year = 2015
13
-
14
- assert_equal(Date.civil(year, 1, 31), @subject.lookup(function, year))
15
- end
16
-
17
- #FIXME This test stinks. I don't know how to show that the second invocation
18
- # doesn't call the function. In rspec I could just do an expect().not_to
19
- # but it doesn't seem like Mocha can do that? I'm punting.
20
- def test_lookup_simply_returns_result_of_cache_if_present_after_first_call
21
- function = lambda { |year| Date.civil(year, 2, 1) - 1 }
22
- year = 2015
23
-
24
- @subject.lookup(function, year)
25
-
26
- assert_equal(Date.civil(year, 1, 31), @subject.lookup(function, year))
27
- end
28
- end
29
-