holidays 4.6.0 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/CONTRIBUTING.md +5 -5
  4. data/Makefile +29 -0
  5. data/README.md +13 -1
  6. data/Rakefile +2 -2
  7. data/definitions/au.yaml +12 -9
  8. data/definitions/ca.yaml +17 -2
  9. data/definitions/ch.yaml +1 -1
  10. data/definitions/index.yaml +3 -0
  11. data/definitions/is.yaml +1 -1
  12. data/definitions/jp.yaml +19 -14
  13. data/definitions/kr.yaml +282 -0
  14. data/definitions/lu.yaml +56 -0
  15. data/definitions/my.yaml +51 -0
  16. data/definitions/ups.yaml +1 -1
  17. data/definitions/us.yaml +1 -1
  18. data/lib/generated_definitions/MANIFEST +3 -0
  19. data/lib/generated_definitions/REGIONS.rb +1 -1
  20. data/lib/generated_definitions/au.rb +11 -8
  21. data/lib/generated_definitions/ca.rb +1 -1
  22. data/lib/generated_definitions/ch.rb +1 -1
  23. data/lib/generated_definitions/europe.rb +2 -2
  24. data/lib/generated_definitions/is.rb +1 -1
  25. data/lib/generated_definitions/jp.rb +13 -15
  26. data/lib/generated_definitions/kr.rb +248 -0
  27. data/lib/generated_definitions/lu.rb +39 -0
  28. data/lib/generated_definitions/my.rb +36 -0
  29. data/lib/generated_definitions/north_america.rb +2 -2
  30. data/lib/generated_definitions/scandinavia.rb +1 -1
  31. data/lib/generated_definitions/ups.rb +1 -1
  32. data/lib/generated_definitions/us.rb +1 -1
  33. data/lib/holidays.rb +29 -51
  34. data/lib/holidays/core_extensions/date.rb +1 -1
  35. data/lib/holidays/definition/context/function_processor.rb +86 -0
  36. data/lib/holidays/definition/context/generator.rb +31 -6
  37. data/lib/holidays/definition/parser/custom_method.rb +1 -3
  38. data/lib/holidays/definition/repository/holidays_by_month.rb +1 -1
  39. data/lib/holidays/definition/validator/region.rb +1 -3
  40. data/lib/holidays/errors.rb +1 -0
  41. data/lib/holidays/factory/date_calculator.rb +37 -0
  42. data/lib/holidays/factory/definition.rb +96 -0
  43. data/lib/holidays/factory/finder.rb +70 -0
  44. data/lib/holidays/finder/context/between.rb +43 -0
  45. data/lib/holidays/{use_case → finder}/context/dates_driver_builder.rb +6 -4
  46. data/lib/holidays/finder/context/next_holiday.rb +57 -0
  47. data/lib/holidays/{option → finder}/context/parse_options.rb +6 -8
  48. data/lib/holidays/finder/context/search.rb +86 -0
  49. data/lib/holidays/finder/context/year_holiday.rb +57 -0
  50. data/lib/holidays/finder/rules/in_region.rb +23 -0
  51. data/lib/holidays/finder/rules/year_range.rb +82 -0
  52. data/lib/holidays/load_all_definitions.rb +7 -5
  53. data/lib/holidays/version.rb +1 -1
  54. data/test/coverage_report.rb +7 -0
  55. data/test/defs/test_defs_au.rb +1 -1
  56. data/test/defs/test_defs_ca.rb +16 -1
  57. data/test/defs/test_defs_jp.rb +4 -0
  58. data/test/defs/test_defs_kr.rb +26 -0
  59. data/test/defs/test_defs_lu.rb +24 -0
  60. data/test/defs/test_defs_my.rb +20 -0
  61. data/test/defs/test_defs_north_america.rb +16 -1
  62. data/test/holidays/core_extensions/test_date_time.rb +7 -7
  63. data/test/holidays/definition/context/test_function_processor.rb +175 -0
  64. data/test/holidays/definition/context/test_generator.rb +18 -11
  65. data/test/holidays/definition/parser/test_custom_method.rb +2 -2
  66. data/test/holidays/definition/repository/test_proc_result_cache.rb +1 -1
  67. data/test/holidays/{test_date_calculator_factory.rb → factory/test_date_calculator.rb} +3 -3
  68. data/test/holidays/factory/test_definition.rb +53 -0
  69. data/test/holidays/factory/test_finder.rb +25 -0
  70. data/test/holidays/finder/context/test_between.rb +172 -0
  71. data/test/holidays/{use_case → finder}/context/test_dates_driver_builder.rb +2 -2
  72. data/test/holidays/finder/context/test_next_holiday.rb +156 -0
  73. data/test/holidays/{option → finder}/context/test_parse_options.rb +9 -9
  74. data/test/holidays/finder/context/test_search.rb +203 -0
  75. data/test/holidays/finder/context/test_year_holiday.rb +202 -0
  76. data/test/holidays/finder/rules/test_in_region.rb +38 -0
  77. data/test/holidays/finder/rules/test_year_range.rb +170 -0
  78. data/test/integration/README.md +9 -0
  79. data/test/{test_all_regions.rb → integration/test_all_regions.rb} +16 -2
  80. data/test/{test_custom_holidays.rb → integration/test_custom_holidays.rb} +2 -2
  81. data/test/{test_custom_year_range_holidays.rb → integration/test_custom_year_range_holidays.rb} +1 -1
  82. data/test/{test_holidays.rb → integration/test_holidays.rb} +43 -32
  83. data/test/{test_holidays_between.rb → integration/test_holidays_between.rb} +8 -16
  84. data/test/{test_multiple_regions.rb → integration/test_multiple_regions.rb} +1 -1
  85. data/test/test_helper.rb +3 -4
  86. metadata +67 -39
  87. data/benchmark.rb +0 -8
  88. data/lib/holidays/date_calculator_factory.rb +0 -35
  89. data/lib/holidays/definition_factory.rb +0 -86
  90. data/lib/holidays/option_factory.rb +0 -15
  91. data/lib/holidays/use_case/context/between.rb +0 -45
  92. data/lib/holidays/use_case/context/context_common.rb +0 -123
  93. data/lib/holidays/use_case/context/next_holiday.rb +0 -54
  94. data/lib/holidays/use_case/context/year_holiday.rb +0 -51
  95. data/lib/holidays/use_case_factory.rb +0 -41
  96. data/test/holidays/test_definition_factory.rb +0 -49
  97. data/test/holidays/test_option_factory.rb +0 -9
  98. data/test/holidays/test_use_case_factory.rb +0 -13
  99. data/test/holidays/use_case/context/test_between.rb +0 -77
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 399d042a1ccc98734480467097210ca85c4bca9c
4
- data.tar.gz: 7e7975f71f2df4d9bf5dacef3ac1e6b14b35ec39
3
+ metadata.gz: 871b08553ee038ed6f91d776fd6f88aca3794f2e
4
+ data.tar.gz: e72de1dec225bd96944fc8bf9999215de0b6a17d
5
5
  SHA512:
6
- metadata.gz: c10f368bebfc2121146d2e89828ff8ee85d93a2135ec2841f4848be47f098e9c5ddc9c6ba9549b1aacc111a34f6b63b721580c7d8a7e76763488e28c1a2ed79e
7
- data.tar.gz: a85d60db955877940d618b61975e6f0d53d3c0e70e01a242196e9fbdfbe743325dacf32cee5f984c0dbadb721ba185f8a518c4bf72c864d63b4c18500b7cf98a
6
+ metadata.gz: 87c05e189fcea4445530190bcdbd32126bbb1af3b4dc7e52de3e71c289ccb5ac014cb1dd1e8d14022634a1a02ac5ba3d32acde7a7df8f5ec700a9217d5f87b9e
7
+ data.tar.gz: 325bb3ec66f2b48c774564aba19bc41c9b3b46ee143cb8f0d5789b30778fa0b34dc04f6af4b97d0c87514a8e1b4ab4426250bb52897637e8f347ec3aa339b4e4
@@ -1,5 +1,10 @@
1
1
  # Ruby Holidays Gem CHANGELOG
2
2
 
3
+ ## 4.7.0
4
+
5
+ * Fix issue-225 (`LocalJumpError` for certain `jp` definition combinations) (https://github.com/ttwo32)
6
+ * Add Korean Lunar holidays (https://github.com/jonathanpike)
7
+
3
8
  ## 4.6.0
4
9
 
5
10
  * Add holidays for 'Luxembourg' (https://github.com/dunyakirkali)
@@ -14,8 +14,8 @@ Here are the steps to take once you have a good idea on what you want to change:
14
14
 
15
15
  * Fork the repository
16
16
  * Edit desired definition YAML file(s) located under `definitions/`. If you are adding a new region be sure to update `definitions/index.yaml` as well
17
- * Run `bundle exec rake generate` to generate updated final definitions (they will be located under `lib/generated_definitions/` and `test/defs/`)
18
- * Run `bundle exec rake test` to ensure your changes did not introduce errors
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
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
20
20
 
21
21
  Including documentation with your updates is very much appreciated. A simple Wikipedia entry or government link in the comments alongside your changes would be perfect.
@@ -36,6 +36,6 @@ Don't worry about versioning, we'll handle it on our end.
36
36
 
37
37
  We have included a few handy tasks to help you troubleshoot and test:
38
38
 
39
- * `rake test` - runs the entire suite
40
- * `rake test_region <region>` - runs the tests for just that region. Make sure to run `rake generate` after updating your YAML before running this!
41
- * `rake console` - launches an IRB session with the 'holidays' gem loaded for quick testing
39
+ * `make test` - runs the entire suite
40
+ * `REGION=<region> make test_region` - runs the tests for just that region. Make sure to run `make generate` after updating your YAML before running this!
41
+ * `make console` - launches an IRB session with the 'holidays' gem loaded for quick testing
@@ -0,0 +1,29 @@
1
+ default: test
2
+
3
+ setup:
4
+ bundle install
5
+
6
+ test:
7
+ bundle exec rake test
8
+
9
+ generate:
10
+ bundle exec rake generate
11
+
12
+ console:
13
+ bundle exec rake console
14
+
15
+ test_region:
16
+ bundle exec rake test_region $(REGION)
17
+
18
+ build:
19
+ bundle exec gem build holidays.gemspec
20
+
21
+ push:
22
+ bundle exec gem push holidays.gemspec
23
+
24
+ clean:
25
+ rm -rf holidays-*.gem
26
+ rm -rf reports
27
+ rm -rf coverage
28
+
29
+ .PHONY: setup test generate
data/README.md CHANGED
@@ -107,7 +107,7 @@ Multiple files can also be passed:
107
107
 
108
108
  Holidays.load_custom('/home/user/holidays/custom_holidays1.yaml', '/home/user/holidays/custom_holidays2.yaml')
109
109
 
110
- ### Extending Ruby's Date class
110
+ ### Extending Ruby's Date and Time classes
111
111
 
112
112
  To extend the 'Date' class:
113
113
 
@@ -136,11 +136,23 @@ Or lookup Canada Day in different regions:
136
136
  d.holiday?(:fr) # France
137
137
  => false
138
138
 
139
+ Or return the new date based on the options:
140
+
141
+ d = Date.civil(2008,7,1)
142
+ d.change(:year => 2016, :month => 1, :day => 1)
143
+ => #<Date: 2016-01-01 ((2457389j,0s,0n),+0s,2299161j)>
144
+
139
145
  Or you can calculate the day of the month:
140
146
 
141
147
  Date.calculate_mday(2015, 4, :first, 2)
142
148
  => 7
143
149
 
150
+ Or find end of month for given date (requires 'Time' extensions as well):
151
+
152
+ d = Date.civil(2016,8,1)
153
+ d.end_of_month
154
+ => #<Date: 2016-08-31 ((2457632j,0s,0n),+0s,2299161j)>
155
+
144
156
  ### Caching Holiday Lookups
145
157
 
146
158
  If you are checking holidays regularly you can cache your results for improved performance. Run this before looking up a holiday (eg. in an initializer):
data/Rakefile CHANGED
@@ -60,8 +60,8 @@ namespace :generate do
60
60
  puts "Building #{region} definition module:"
61
61
  files = files.collect { |f| "#{DEFINITION_PATH}/#{f}" }.uniq
62
62
 
63
- regions, rules_by_month, custom_methods, tests = Holidays::DefinitionFactory.file_parser.parse_definition_files(files)
64
- module_src, test_src = Holidays::DefinitionFactory.source_generator.generate_definition_source(region, files, regions, rules_by_month, custom_methods, tests)
63
+ regions, rules_by_month, custom_methods, tests = Holidays::Factory::Definition.file_parser.parse_definition_files(files)
64
+ module_src, test_src = Holidays::Factory::Definition.source_generator.generate_definition_source(region, files, regions, rules_by_month, custom_methods, tests)
65
65
 
66
66
  File.open("lib/#{Holidays::DEFINITIONS_PATH}/#{region.downcase.to_s}.rb","w") do |file|
67
67
  file.puts module_src
@@ -169,8 +169,11 @@ methods:
169
169
  afl_grand_final:
170
170
  arguments: year
171
171
  source: |
172
- if year == 2015
172
+ case year
173
+ when 2015
173
174
  Date.civil(2015, 10, 2)
175
+ when 2016
176
+ Date.civil(2017, 9, 30)
174
177
  end
175
178
  qld_queens_bday_october:
176
179
  # http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
@@ -179,7 +182,7 @@ methods:
179
182
  arguments: year
180
183
  source: |
181
184
  if year >= 2016
182
- DateCalculatorFactory.day_of_month_calculator.call(year, 10, 1, 1)
185
+ Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 1, 1)
183
186
  elsif year == 2012
184
187
  1
185
188
  else
@@ -191,7 +194,7 @@ methods:
191
194
  arguments: year
192
195
  source: |
193
196
  if year <= 2015
194
- DateCalculatorFactory.day_of_month_calculator.call(year, 6, 2, 1)
197
+ Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 6, 2, 1)
195
198
  end
196
199
  qld_labour_day_may:
197
200
  # http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
@@ -199,7 +202,7 @@ methods:
199
202
  arguments: year
200
203
  source: |
201
204
  if year < 2013 || year >= 2016
202
- DateCalculatorFactory.day_of_month_calculator.call(year, 5, 1, 1)
205
+ Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 5, 1, 1)
203
206
  end
204
207
  qld_labour_day_october:
205
208
  # http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
@@ -207,7 +210,7 @@ methods:
207
210
  arguments: year
208
211
  source: |
209
212
  if year >= 2013 && year < 2016
210
- DateCalculatorFactory.day_of_month_calculator.call(year, 10, 1, 1)
213
+ Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 1, 1)
211
214
  end
212
215
  g20_day_2014_only:
213
216
  # http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
@@ -220,7 +223,7 @@ methods:
220
223
  # The Thursday before the fourth Saturday in October.
221
224
  arguments: year
222
225
  source: |
223
- fourth_sat_in_oct = Date.civil(year, 10, Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 10, 4, :saturday))
226
+ fourth_sat_in_oct = Date.civil(year, 10, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 4, :saturday))
224
227
  fourth_sat_in_oct - 2 # the thursday before
225
228
  march_pub_hol_sa:
226
229
  # http://www.safework.sa.gov.au/show_page.jsp?id=2483#.VQ9Mfmb8-8E
@@ -230,7 +233,7 @@ methods:
230
233
  if year < 2006
231
234
  nil
232
235
  else
233
- Date.civil(year, 3, Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 3, :second, :monday))
236
+ Date.civil(year, 3, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 3, :second, :monday))
234
237
  end
235
238
  may_pub_hol_sa:
236
239
  # http://www.safework.sa.gov.au/show_page.jsp?id=2483#.VQ9Mfmb8-8E
@@ -240,7 +243,7 @@ methods:
240
243
  if year >= 2006
241
244
  nil
242
245
  else
243
- Date.civil(year, 5, Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 5, :third, :monday))
246
+ Date.civil(year, 5, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 5, :third, :monday))
244
247
  end
245
248
 
246
249
  tests: |
@@ -312,7 +315,7 @@ tests: |
312
315
  assert_equal 'Melbourne Cup Day', Holidays.on(Date.civil(2015,11,3), :au_vic_melbourne)[0][:name]
313
316
 
314
317
  assert_equal 'Friday before the AFL Grand Final', Date.civil(2015,10,2).holidays(:au_vic)[0][:name]
315
- assert_nil Date.civil(2016,10,2).holidays(:au_vic)[0]
318
+ assert_equal 'Friday before the AFL Grand Final', Date.civil(2016,9, 30).holidays(:au_vic)[0][:name]
316
319
 
317
320
  assert_equal "May Public Holiday", Date.civil(2005, 5, 16).holidays(:au_sa)[0][:name]
318
321
  assert_equal [], Date.civil(2014, 5, 19).holidays(:au_sa)
@@ -141,7 +141,7 @@ months:
141
141
  wday: 1
142
142
  11:
143
143
  - name: Remembrance Day
144
- regions: [ca]
144
+ regions: [ ca_ab, ca_sk, ca_bc, ca_pe, ca_nf, ca_nt, ca_nu, ca_nb, ca_yk]
145
145
  mday: 11
146
146
  12:
147
147
  - name: Christmas Day
@@ -171,7 +171,6 @@ tests: |
171
171
  Date.civil(2008,7,1) => 'Canada Day',
172
172
  Date.civil(2008,9,1) => 'Labour Day',
173
173
  Date.civil(2008,10,13) => 'Thanksgiving',
174
- Date.civil(2008,11,11) => 'Remembrance Day',
175
174
  Date.civil(2008,12,25) => 'Christmas Day',
176
175
  Date.civil(2008,12,26) => 'Boxing Day'}.each do |date, name|
177
176
  assert_equal name, (Holidays.on(date, :ca, :informal)[0] || {})[:name]
@@ -300,3 +299,19 @@ tests: |
300
299
  assert_equal name, Holidays.on(date, region)[0][:name]
301
300
  end
302
301
  end
302
+
303
+ # Remembrance Day in all Canadian provinces
304
+ # except (Nova Scotia, Manitoba, Ontario, and Quebec)
305
+ [
306
+ :ca_ab,
307
+ :ca_sk,
308
+ :ca_bc,
309
+ :ca_pe,
310
+ :ca_nf,
311
+ :ca_nt,
312
+ :ca_nu,
313
+ :ca_nb,
314
+ :ca_yk
315
+ ].each do |province|
316
+ assert_equal "Remembrance Day", Holidays.on(Date.civil(2016,11,11), province)[0][:name]
317
+ end
@@ -159,7 +159,7 @@ methods:
159
159
  date += 1
160
160
  end
161
161
 
162
- if date.eql?(Holidays::DateCalculatorFactory::Easter::Gregorian.easter_calculator.calculate_easter_for(year)-3)
162
+ if date.eql?(Holidays::Factory::DateCalculator::Easter::Gregorian.easter_calculator.calculate_easter_for(year)-3)
163
163
  date += 7
164
164
  end
165
165
  date
@@ -28,12 +28,14 @@ defs:
28
28
  IE: ['ie.yaml']
29
29
  IS: ['is.yaml']
30
30
  IT: ['it.yaml']
31
+ KR: ['kr.yaml']
31
32
  LI: ['li.yaml']
32
33
  LT: ['lt.yaml']
33
34
  MA: ['ma.yaml']
34
35
  MX: ['mx.yaml', 'north_america_informal.yaml']
35
36
  NERC: ['nerc.yaml']
36
37
  NL: ['nl.yaml']
38
+ LU: ['lu.yaml']
37
39
  "NO": ['no.yaml']
38
40
  NYSE: ['nyse.yaml']
39
41
  NZ: ['nz.yaml']
@@ -56,3 +58,4 @@ defs:
56
58
  SK: ['sk.yaml']
57
59
  SI: ['si.yaml']
58
60
  SG: ['sg.yaml']
61
+ MY: ['my.yaml']
@@ -117,7 +117,7 @@ methods:
117
117
  date = Date.civil(year,4,18)
118
118
  if date.wday < 4
119
119
  date += (4 - date.wday)
120
- else date
120
+ else
121
121
  date += (11 - date.wday)
122
122
  end
123
123
  date
@@ -119,6 +119,8 @@ months:
119
119
  function: jp_respect_for_aged_holiday_substitute(year)
120
120
  - name: 国民の休日
121
121
  regions: [jp]
122
+ year_ranges:
123
+ - after: 2003
122
124
  function: jp_citizens_holiday(year)
123
125
  - name: 秋分の日
124
126
  regions: [jp]
@@ -162,7 +164,7 @@ methods:
162
164
  jp_health_sports_day_substitute:
163
165
  arguments: year
164
166
  source: |
165
- Holidays::DefinitionFactory.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 10, Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 10, 2, 1))
167
+ Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 10, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 2, 1))
166
168
  jp_vernal_equinox_day:
167
169
  arguments: year
168
170
  source: |
@@ -185,12 +187,12 @@ methods:
185
187
  jp_vernal_equinox_day_substitute:
186
188
  arguments: year
187
189
  source: |
188
- date = Holidays::DefinitionFactory.custom_methods_repository.find("jp_vernal_equinox_day(year)").call(year)
189
- Holidays::DefinitionFactory.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
190
+ date = Holidays::Factory::Definition.custom_methods_repository.find("jp_vernal_equinox_day(year)").call(year)
191
+ Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
190
192
  jp_marine_day_substitute:
191
193
  arguments: year
192
194
  source: |
193
- Holidays::DefinitionFactory.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 7, Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 7, 3, 1))
195
+ Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 7, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 7, 3, 1))
194
196
  jp_national_culture_day:
195
197
  arguments: year
196
198
  source: |
@@ -213,13 +215,12 @@ methods:
213
215
  jp_national_culture_day_substitute:
214
216
  arguments: year
215
217
  source: |
216
- date = Holidays::DefinitionFactory.custom_methods_repository.find("jp_national_culture_day(year)").call(year)
217
- Holidays::DefinitionFactory.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
218
+ date = Holidays::Factory::Definition.custom_methods_repository.find("jp_national_culture_day(year)").call(year)
219
+ Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
218
220
  jp_citizens_holiday:
219
221
  arguments: year
220
222
  source: |
221
- year < 2003 and return nil
222
- ncd = Holidays::DefinitionFactory.custom_methods_repository.find("jp_national_culture_day(year)").call(year)
223
+ ncd = Holidays::Factory::Definition.custom_methods_repository.find("jp_national_culture_day(year)").call(year)
223
224
  if ncd.wday == 3
224
225
  ncd - 1
225
226
  else
@@ -228,29 +229,28 @@ methods:
228
229
  jp_mountain_holiday:
229
230
  arguments: year
230
231
  source: |
231
- return nil if year < 2016
232
232
  Date.civil(year, 8, 11)
233
233
  jp_mountain_holiday_substitute:
234
234
  arguments: year
235
235
  source: |
236
- date = Holidays::DefinitionFactory.custom_methods_repository.find("jp_mountain_holiday(year)").call(year)
237
- Holidays::DefinitionFactory.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
236
+ date = Holidays::Factory::Definition.custom_methods_repository.find("jp_mountain_holiday(year)").call(year)
237
+ Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
238
238
  jp_respect_for_aged_holiday_substitute:
239
239
  arguments: year
240
240
  source: |
241
- Holidays::DefinitionFactory.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 9, Holidays::DateCalculatorFactory.day_of_month_calculator.call(year, 9, 3, 1))
241
+ Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 9, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 9, 3, 1))
242
242
  jp_substitute_holiday:
243
243
  arguments: year, month, day
244
244
  source: |
245
245
  date = Date.civil(year, month, day)
246
- date.wday == 0 ? (Holidays::DefinitionFactory.custom_methods_repository.find("jp_next_weekday(date)").call(date+1)) : nil
246
+ date.wday == 0 ? (Holidays::Factory::Definition.custom_methods_repository.find("jp_next_weekday(date)").call(date+1)) : nil
247
247
  jp_next_weekday:
248
248
  arguments: date
249
249
  source: |
250
250
  is_holiday = Holidays::JP.holidays_by_month[date.month].any? do |holiday|
251
251
  holiday[:mday] == date.day
252
252
  end
253
- date.wday == 0 || is_holiday ? (Holidays::DefinitionFactory.custom_methods_repository.find("jp_next_weekday(date)").call(date+1)) : date
253
+ date.wday == 0 || is_holiday ? (Holidays::Factory::Definition.custom_methods_repository.find("jp_next_weekday(date)").call(date+1)) : date
254
254
 
255
255
  tests: |
256
256
  {Date.civil(2008,1,1) => '元日',
@@ -314,3 +314,8 @@ tests: |
314
314
 
315
315
  # before 2016, there is no mountain holiday.
316
316
  assert_nil Holidays.on(Date.civil(2015,8,11), :jp)[0]
317
+
318
+ # before 2003, there is no citizens holiday.
319
+ # [note] citizens holiday requires that jp_national_culture_day is wednesday.
320
+ # Before 2003, the closest past year that mathches above condition is 1998.
321
+ assert_nil Holidays.on(Date.civil(1998,9,22), :jp)[0]
@@ -0,0 +1,282 @@
1
+ # Republic of Korea holiday definitions for the Ruby Holiday gem.
2
+ # Provided by Jonathan Pike
3
+ #
4
+ # Updated: 2016-09-23.
5
+ # Sources:
6
+ # - https://en.wikipedia.org/wiki/List_of_public_holidays_in_South_Korea
7
+ # - http://www.hko.gov.hk/gts/time/conversion.htm (for Lunar Calendar Conversions)
8
+
9
+ ---
10
+ months:
11
+ 0:
12
+ - name: Korean New Year
13
+ regions: [kr]
14
+ function: kr_new_years(year)
15
+ - name: Buddah's Birthday
16
+ regions: [kr]
17
+ function: kr_buddahs_birthday(year)
18
+ - name: Korean Thanksgiving
19
+ regions: [kr]
20
+ function: kr_thanksgiving(year)
21
+ 1:
22
+ - name: New Year's Day
23
+ regions: [kr]
24
+ mday: 1
25
+ 3:
26
+ - name: Independence Movement Day
27
+ regions: [kr]
28
+ mday: 1
29
+ 5:
30
+ - name: Children's Day
31
+ regions: [kr]
32
+ mday: 5
33
+ 6:
34
+ - name: Memorial Day
35
+ regions: [kr]
36
+ mday: 6
37
+ 7:
38
+ - name: Constitution Day
39
+ regions: [kr]
40
+ mday: 17
41
+ type: informal
42
+ 8:
43
+ - name: Liberation Day
44
+ regions: [kr]
45
+ mday: 15
46
+ 10:
47
+ - name: National Foundation Day
48
+ regions: [kr]
49
+ mday: 3
50
+ - name: Hangul Day
51
+ regions: [kr]
52
+ mday: 9
53
+ 12:
54
+ - name: Christmas Day
55
+ regions: [kr]
56
+ mday: 25
57
+
58
+ methods:
59
+ kr_new_years:
60
+ arguments: year
61
+ source: |
62
+ month_day = case year
63
+ when 1941
64
+ [1, 17]
65
+ when 1966
66
+ [1, 21]
67
+ when 1909, 1947, 2004, 2023, 2042
68
+ [1, 22]
69
+ when 1917, 1928, 1974, 1993, 2012, 2031, 2015
70
+ [1, 23]
71
+ when 1925, 1936, 1955, 2001, 2039
72
+ [1, 24]
73
+ when 1906, 1944, 1963, 1982, 2020
74
+ [1, 25]
75
+ when 1914, 1933, 2009, 2028, 2047
76
+ [1, 26]
77
+ when 1952, 1971, 1990
78
+ [1, 27]
79
+ when 1922, 1960, 1979, 1998, 2017, 2036
80
+ [1, 28]
81
+ when 1903, 1949, 1987, 2006, 2025
82
+ [1, 29]
83
+ when 1911, 1930, 1968, 2044
84
+ [1, 30]
85
+ when 1938, 1957, 1976, 1995, 2014, 2033
86
+ [1, 31]
87
+ when 1919, 1948, 2003, 2022, 2041
88
+ [2, 1]
89
+ when 1908, 1927, 1946, 1965, 1984, 2049
90
+ [2, 2]
91
+ when 1916, 1954, 1973, 2011, 2030
92
+ [2, 3]
93
+ when 1905, 1935, 1992, 2038
94
+ [2, 4]
95
+ when 1924, 1943, 1962, 1981, 1989, 2000, 2019
96
+ [2, 5]
97
+ when 1913, 1932, 1951, 1970, 2027, 2046
98
+ [2, 6]
99
+ when 1978, 1997, 2008
100
+ [2, 7]
101
+ when 1902, 1921, 1940, 1959, 2016, 2035
102
+ [2, 8]
103
+ when 1967, 1986, 2005
104
+ [2, 9]
105
+ when 1910, 1929, 1994, 2013, 2024, 2043
106
+ [2, 10]
107
+ when 1918, 1937, 1975, 2032
108
+ [2, 11]
109
+ when 1956, 2002, 2021, 2040
110
+ [2, 12]
111
+ when 1907, 1926, 1945, 1964, 1983, 2029
112
+ [2, 13]
113
+ when 1915, 1934, 1953, 2010, 2048
114
+ [2, 14]
115
+ when 1942, 1961, 1972, 1991, 2037
116
+ [2, 15]
117
+ when 1904, 1923, 1980, 1999, 2018
118
+ [2, 16]
119
+ when 1931, 1950, 1969, 1988, 2026, 2045
120
+ [2, 17]
121
+ when 1912, 1958, 1977, 2007
122
+ [2, 18]
123
+ when 1901, 1939, 1996, 2015, 2034
124
+ [2, 19]
125
+ when 1920, 1985
126
+ [2, 20]
127
+ end
128
+ Date.civil(year, month_day[0], month_day[1])
129
+
130
+ kr_buddahs_birthday:
131
+ arguments: year
132
+ source: |
133
+ month_day = case year
134
+ when 2039
135
+ [4, 30]
136
+ when 1952, 1963, 1982
137
+ [5, 1]
138
+ when 1914, 1933, 1971, 1990, 2009, 2028, 2047
139
+ [5, 2]
140
+ when 1941, 1960, 1979, 1998, 2017, 2036
141
+ [5, 3]
142
+ when 1901, 1903, 1922, 1968
143
+ [5, 4]
144
+ when 1949, 1987, 2006, 2012, 2025, 2044
145
+ [5, 5]
146
+ when 1911, 1930, 1976, 2014, 2033
147
+ [5, 6]
148
+ when 1908, 1919, 1957, 1995, 2041
149
+ [5, 7]
150
+ when 1927, 1946, 1965, 1984, 2003, 2022
151
+ [5, 8]
152
+ when 1916, 2030, 2049
153
+ [5, 9]
154
+ when 1935, 1954, 1973, 1992, 2011
155
+ [5, 10]
156
+ when 1905, 1924, 1943, 1962, 1981, 2000, 2038
157
+ [5, 11]
158
+ when 1970, 1989, 2008, 2019
159
+ [5, 12]
160
+ when 1913, 1932, 1951, 2027
161
+ [5, 13]
162
+ when 1938, 1940, 1978, 1997, 2016
163
+ [5, 14]
164
+ when 1902, 1921, 1959, 2005, 2024, 2035
165
+ [5, 15]
166
+ when 1910, 1929, 1948, 1967, 1986, 2032, 2043
167
+ [5, 16]
168
+ when 1918, 1937, 1956, 2013
169
+ [5, 17]
170
+ when 1975, 1994, 2040
171
+ [5, 18]
172
+ when 1907, 1926, 1945, 1964, 2002, 2021
173
+ [5, 19]
174
+ when 1934, 1953, 1972, 1983, 2029, 2046, 2048
175
+ [5, 20]
176
+ when 1915, 1980, 1991, 2010
177
+ [5, 21]
178
+ when 1904, 1942, 1961, 1999, 2018, 2037
179
+ [5, 22]
180
+ when 1923, 1969, 1988
181
+ [5, 23]
182
+ when 1912, 1931, 1950, 1996, 2007, 2026, 2045
183
+ [5, 24]
184
+ when 1920, 1977, 2015, 2034
185
+ [5, 25]
186
+ when 1909, 1928, 1939, 1947, 1958, 2004, 2023, 2042
187
+ [5, 26]
188
+ when 1966, 1985
189
+ [5, 27]
190
+ when 1917, 1936, 1993, 2031, 2050
191
+ [5, 28]
192
+ when 1925, 1944, 1955, 1974
193
+ [5, 29]
194
+ when 1906, 2001, 2020
195
+ [5, 30]
196
+ end
197
+ Date.civil(year, month_day[0], month_day[1])
198
+
199
+ kr_thanksgiving:
200
+ arguments: year
201
+ source: |
202
+ month_day = case year
203
+ when 1905, 1924, 1973
204
+ [9, 8]
205
+ when 1913, 1970, 1989, 2000, 2008, 2019, 2038
206
+ [9, 10]
207
+ when 1902, 1932, 1938, 1981, 2027
208
+ [9, 11]
209
+ when 1929, 1940, 1951, 1978, 2016, 2035
210
+ [9, 12]
211
+ when 1921, 1948, 1959, 1997, 2024
212
+ [9, 13]
213
+ when 1910, 1975, 2005
214
+ [9, 14]
215
+ when 1918, 1937, 1945, 1967, 1986, 2032, 2043
216
+ [9, 15]
217
+ when 1907, 1964, 1994, 2013, 2040
218
+ [9, 16]
219
+ when 1926, 1956, 1962, 1972, 2046, 2048
220
+ [9, 17]
221
+ when 1934, 1953, 2002, 2021
222
+ [9, 18]
223
+ when 1904, 1915, 1980, 2010, 2029
224
+ [9, 19]
225
+ when 1923, 1969, 1983, 1991, 1999
226
+ [9, 20]
227
+ when 1942, 1961, 1988, 2037
228
+ [9, 21]
229
+ when 1912, 1977 ,1996, 2007, 2015, 2018, 2026
230
+ [9, 22]
231
+ when 1931, 1939, 1950
232
+ [9, 23]
233
+ when 1909, 1920, 1947, 1958, 2034, 2045
234
+ [9, 24]
235
+ when 1917, 1928, 1936, 1966, 1985, 2050
236
+ [9, 25]
237
+ when 2001, 2004, 2023, 2042
238
+ [9, 26]
239
+ when 1906, 1925, 1944, 1955, 1974, 1993, 2031
240
+ [9, 27]
241
+ when 1914, 1963, 1971, 2009
242
+ [9, 28]
243
+ when 1933, 1952, 1982, 2020
244
+ [9, 29]
245
+ when 1941, 1979, 1990, 2017, 2028, 2036, 2047
246
+ [9, 30]
247
+ when 1901, 1960, 1968, 1987, 2006
248
+ [10, 1]
249
+ when 1903, 1922, 1949, 1998
250
+ [10, 2]
251
+ when 1911, 1976, 2014, 2033, 2044
252
+ [10, 3]
253
+ when 1927, 1930, 2012, 2025, 2041
254
+ [10, 4]
255
+ when 1908, 1919, 1935, 1946, 1957, 1995, 2039
256
+ [10, 5]
257
+ when 1916, 1965, 2003, 2022, 2030, 2049
258
+ [10, 6]
259
+ when 1984
260
+ [10, 7]
261
+ when 1943, 1954, 1992
262
+ [10, 8]
263
+ when 2011
264
+ [10, 9]
265
+ end
266
+ Date.civil(year, month_day[0], month_day[1])
267
+
268
+ tests: |
269
+ {Date.civil(2016,2,8) => "Korean New Year",
270
+ Date.civil(2016,5,14) => "Buddah\'s Birthday",
271
+ Date.civil(2016,9,12) => "Korean Thanksgiving",
272
+ Date.civil(2016,1,1) => "New Year\'s Day",
273
+ Date.civil(2016,3,1) => "Independence Movement Day",
274
+ Date.civil(2016,5,5) => "Children\'s Day",
275
+ Date.civil(2016,6,6) => "Memorial Day",
276
+ Date.civil(2016,7,17) => "Constitution Day",
277
+ Date.civil(2016,8,15) => "Liberation Day",
278
+ Date.civil(2016,10,3) => "National Foundation Day",
279
+ Date.civil(2016,10,9) => "Hangul Day",
280
+ Date.civil(2016,12,25) => "Christmas Day"}.each do |date, name|
281
+ assert_equal name, (Holidays.on(date, :kr, :informal)[0] || {})[:name]
282
+ end