holidays 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7ac864cf9a702e79f70f0781f4a9f0739a7909c
4
- data.tar.gz: b2f694914ebcf0cd36a7e5b531fd3cc3a9aec3b3
3
+ metadata.gz: 77b3290ef77ac73e4c81a51e2d74b2b68ef60533
4
+ data.tar.gz: f72a5fde80cdbfd9162900fd3d136a19021ae813
5
5
  SHA512:
6
- metadata.gz: 2478e61ae75f0d08de0b50c1d7f7a8ec214efc2a919fae11f86866a1fa8c9834b322cef0728fa754fffa32470282ebec807fbe97844e6cb3f911bbb50db3792a
7
- data.tar.gz: 01d5ff2c9345147b92c6f13fa7c009f52dfb7939f9c133da9ba36878c6164c957e1ddea81a56a9b31eeaf4cf0bf4cbb0b4199274a9b6027fcade5551a6b941e0
6
+ metadata.gz: e31642097c28e4b700ec95fe24ee45130df17293024068bddd78f574501b65dced6c5dc54c86eb53c27ecd4e5eff802830b6db216f51443fbcd34ac1813fe2c5
7
+ data.tar.gz: e8277aacc33b835caa5b7404f9e348ac5533355fb99113b596a20081c0a64714c677a30ce478ab156cb2b58e92fc5d63c26d042a080132baffdeb9318405c818
@@ -1,5 +1,10 @@
1
1
  # Ruby Holidays Gem CHANGELOG
2
2
 
3
+ ## 5.1.0
4
+
5
+ * Add `load_all` method to `Holidays` namespace to preload all definitions (i.e. no lazy loading)
6
+ * Fix issue-234: correctly load available regions so there is no error on `Holidays.available_regions` call
7
+
3
8
  ## 5.0.0
4
9
 
5
10
  * Remove support for jruby 1.7 (this is the main reason for the major semver bump)
@@ -9,44 +9,6 @@ require 'holidays/factory/finder'
9
9
  require 'holidays/errors'
10
10
  require 'holidays/load_all_definitions'
11
11
 
12
- # == Region options
13
- # Holidays can be defined as belonging to one or more regions and sub regions.
14
- # The Holidays#on, Holidays#between, Date#holidays and Date#holiday? methods
15
- # each allow you to specify a specific region.
16
- #
17
- # There are several different ways that you can specify a region:
18
- #
19
- # [<tt>:region</tt>]
20
- # By region. For example, return holidays in the Canada with <tt>:ca</tt>.
21
- # [<tt>:region_</tt>]
22
- # By region and sub regions. For example, return holidays in Germany
23
- # and all its sub regions with <tt>:de_</tt>.
24
- # [<tt>:region_sub</tt>]
25
- # By sub region. Return national holidays in Spain plus holidays in Spain's
26
- # Valencia region with <tt>:es_v</tt>.
27
- # [<tt>:any</tt>]
28
- # Any region. Return holidays from any loaded region.
29
- #
30
- #
31
- # You can load all the available holiday definition sets by running
32
- # Holidays.load_all
33
- # == Other options
34
- # [<tt>:observed</tt>] Return holidays on the day they are observed (e.g. on a Monday if they fall on a Sunday).
35
- # [<tt>:informal</tt>] Include informal holidays (e.g. Valentine's Day)
36
- #
37
- # == Examples
38
- # Return all holidays in the <tt>:ca</tt> and <tt>:us</tt> regions on the day that they are
39
- # observed.
40
- #
41
- # Holidays.between(from, to, :ca, :us, :observed)
42
- #
43
- # Return all holidays in <tt>:ca</tt> and any <tt>:ca</tt> sub-region.
44
- #
45
- # Holidays.between(from, to, :ca_)
46
- #
47
- # Return all holidays in <tt>:ca_bc</tt> sub-region (which includes the <tt>:ca</tt>), including informal holidays.
48
- #
49
- # Holidays.between(from, to, :ca_bc, :informal)
50
12
  module Holidays
51
13
  WEEKS = {:first => 1, :second => 2, :third => 3, :fourth => 4, :fifth => 5, :last => -1, :second_last => -2, :third_last => -3}
52
14
  MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
@@ -56,13 +18,6 @@ module Holidays
56
18
  FULL_DEFINITIONS_PATH = File.expand_path(File.dirname(__FILE__) + "/#{DEFINITIONS_PATH}")
57
19
 
58
20
  class << self
59
- # Does the given work-week have any holidays?
60
- #
61
- # [<tt>date</tt>] A Date object.
62
- # [<tt>:options</tt>] One or more region symbols, and/or <tt>:informal</tt>. Automatically includes <tt>:observed</tt>. If you don't want this, pass <tt>:no_observed</tt>
63
- #
64
- # The given Date can be any day of the week.
65
- # Returns true if any holidays fall on Monday - Friday of the given week.
66
21
  def any_holidays_during_work_week?(date, *options)
67
22
  days_to_monday = date.wday - 1
68
23
  days_to_friday = 5 - date.wday
@@ -73,35 +28,10 @@ module Holidays
73
28
  between(start_date, end_date, options).empty?
74
29
  end
75
30
 
76
- # Get all holidays on a given date.
77
- #
78
- # [<tt>date</tt>] A Date object.
79
- # [<tt>:options</tt>] One or more region symbols, <tt>:informal</tt> and/or <tt>:observed</tt>.
80
- #
81
- # Returns an array of hashes or nil. See Holidays#between for the output
82
- # format.
83
- #
84
- # Also available via Date#holidays.
85
31
  def on(date, *options)
86
32
  between(date, date, options)
87
33
  end
88
34
 
89
- # Get all holidays occuring between two dates, inclusively.
90
- #
91
- # Returns an array of hashes or nil.
92
- #
93
- # Each holiday is returned as a hash with the following fields:
94
- # [<tt>start_date</tt>] Ruby Date object.
95
- # [<tt>end_date</tt>] Ruby Date object.
96
- # [<tt>options</tt>] One or more region symbols, <tt>:informal</tt> and/or <tt>:observed</tt>.
97
- #
98
- # ==== Example
99
- # from = Date.civil(2008,7,1)
100
- # to = Date.civil(2008,7,31)
101
- #
102
- # Holidays.between(from, to, :ca, :us)
103
- # => [{:name => 'Canada Day', :regions => [:ca]...}
104
- # {:name => 'Independence Day'', :regions => [:us], ...}]
105
35
  def between(start_date, end_date, *options)
106
36
  raise ArgumentError unless start_date && end_date
107
37
 
@@ -118,25 +48,6 @@ module Holidays
118
48
  Factory::Finder.between.call(start_date, end_date, options)
119
49
  end
120
50
 
121
- # Get next holidays occuring from date, inclusively.
122
- #
123
- # Returns an array of hashes or nil.
124
- #
125
- # Incoming arguments are below:
126
- # [<tt>holidays_count</tt>] Ruby Numeric object. This is the number of holidays to return
127
- # [<tt>options</tt>] One or more region symbols, <tt>:informal</tt> and/or <tt>:observed</tt>.
128
- # [<tt>from_date</tt>] Ruby Date object. This is an optional param, defaulted today.
129
- #
130
- # ==== Example
131
- # Date.today
132
- # => Tue, 23 Feb 2016
133
- #
134
- # regions = [:us, :informal]
135
- #
136
- # Holidays.next_holidays(3, regions)
137
- # => [{:name => "St. Patrick's Day",...},
138
- # {:name => "Good Friday",...},
139
- # {:name => "Easter Sunday",...}]
140
51
  def next_holidays(holidays_count, options, from_date = Date.today)
141
52
  raise ArgumentError unless holidays_count
142
53
  raise ArgumentError if options.empty?
@@ -150,31 +61,6 @@ module Holidays
150
61
  Factory::Finder.next_holiday.call(holidays_count, from_date, options)
151
62
  end
152
63
 
153
- # Get all holidays occuring from date to end of year, inclusively.
154
- #
155
- # Returns an array of hashes or nil.
156
- #
157
- # Incoming arguments are below:
158
- # [<tt>options</tt>] One or more region symbols, <tt>:informal</tt> and/or <tt>:observed</tt>.
159
- # [<tt>from_date</tt>] Ruby Date object. This is an optional param, defaulted today.
160
- #
161
- # ==== Example
162
- # Date.today
163
- # => Tue, 23 Feb 2016
164
- #
165
- # regions = [:ca_on]
166
- #
167
- # Holidays.year_holidays(regions)
168
- # => [{:name=>"Good Friday",...},
169
- # {name=>"Easter Sunday",...},
170
- # {:name=>"Victoria Day",...},
171
- # {:name=>"Canada Day",...},
172
- # {:name=>"Civic Holiday",...},
173
- # {:name=>"Labour Day",...},
174
- # {:name=>"Thanksgiving",...},
175
- # {:name=>"Remembrance Day",...},
176
- # {:name=>"Christmas Day",...},
177
- # {:name=>"Boxing Day",...}]
178
64
  def year_holidays(options, from_date = Date.today)
179
65
  raise ArgumentError if options.empty?
180
66
  raise ArgumentError unless options.is_a?(Array)
@@ -186,7 +72,6 @@ module Holidays
186
72
  Factory::Finder.year_holiday.call(from_date, options)
187
73
  end
188
74
 
189
- # Allows a developer to explicitly calculate and cache holidays within a given period
190
75
  def cache_between(start_date, end_date, *options)
191
76
  start_date, end_date = get_date(start_date), get_date(end_date)
192
77
  cache_data = between(start_date, end_date, *options)
@@ -194,12 +79,11 @@ module Holidays
194
79
  Factory::Definition.cache_repository.cache_between(start_date, end_date, cache_data, options)
195
80
  end
196
81
 
197
- # Returns an array of symbols of all the available holiday regions.
198
82
  def available_regions
83
+ require "#{DEFINITIONS_PATH}/REGIONS"
199
84
  Holidays::REGIONS
200
85
  end
201
86
 
202
- # Parses provided holiday definition file(s) and loads them so that they are immediately available.
203
87
  def load_custom(*files)
204
88
  regions, rules_by_month, custom_methods, _ = Factory::Definition.file_parser.parse_definition_files(files)
205
89
 
@@ -212,6 +96,19 @@ module Holidays
212
96
  rules_by_month
213
97
  end
214
98
 
99
+ def load_all
100
+ path = FULL_DEFINITIONS_PATH + "/"
101
+
102
+ Dir.foreach(path) do |item|
103
+ next if item == '.' or item == '..'
104
+
105
+ target = path+item
106
+ next if File.extname(target) != '.rb'
107
+
108
+ require target
109
+ end
110
+ end
111
+
215
112
  private
216
113
 
217
114
  def get_date(date)
@@ -1,3 +1,3 @@
1
1
  module Holidays
2
- VERSION = '5.0.0'
2
+ VERSION = '5.1.0'
3
3
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  These tests are dependent on the files in /definitions (and, by proxy, /lib/generated_definitions).
4
4
  It is possible that these tests will break because of 'unrelated' definition changes. The code
5
- behind these changes could still be good but since the defintions changed we could see failures.
5
+ behind these changes could still be good but since the definitions changed we could see failures.
6
6
 
7
7
  These are not unit tests. This is not testing whether specific internal code is working. These are
8
8
  tests from the consumer perspective. You must recognize that this could fail because of code
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
+
3
+ class AvailableRegionsTests < Test::Unit::TestCase
4
+ def setup
5
+ @date = Date.civil(2008,1,1)
6
+ end
7
+
8
+ def test_available_regions_returns_array
9
+ assert Holidays.available_regions.is_a?(Array)
10
+ end
11
+
12
+ def test_available_regions_returns_array_of_symbols
13
+ Holidays.available_regions.each do |r|
14
+ assert r.is_a?(Symbol)
15
+ end
16
+ end
17
+
18
+ # This test might fail if we add new regions. Since this is an integration test
19
+ # I am fine with that!
20
+ def test_available_regions_returns_correct_number_of_regions
21
+ assert_equal 294, Holidays.available_regions.count
22
+ end
23
+ end
@@ -281,4 +281,9 @@ class HolidaysTests < Test::Unit::TestCase
281
281
  assert_equal 1, Holidays.on(Date.civil(2035,1,1), :ca, :informal).length
282
282
  assert_equal 1, Holidays.on(Date.civil(2035,1,1), :us).length
283
283
  end
284
+
285
+ def test_load_all
286
+ Holidays.load_all
287
+ assert_equal 294, Holidays.available_regions.count
288
+ end
284
289
  end
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: 5.0.0
4
+ version: 5.1.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-09-24 00:00:00.000000000 Z
12
+ date: 2016-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -310,6 +310,7 @@ files:
310
310
  - test/holidays/finder/rules/test_year_range.rb
311
311
  - test/integration/README.md
312
312
  - test/integration/test_all_regions.rb
313
+ - test/integration/test_available_regions.rb
313
314
  - test/integration/test_custom_holidays.rb
314
315
  - test/integration/test_custom_year_range_holidays.rb
315
316
  - test/integration/test_holidays.rb
@@ -439,6 +440,7 @@ test_files:
439
440
  - test/holidays/finder/rules/test_year_range.rb
440
441
  - test/integration/README.md
441
442
  - test/integration/test_all_regions.rb
443
+ - test/integration/test_available_regions.rb
442
444
  - test/integration/test_custom_holidays.rb
443
445
  - test/integration/test_custom_year_range_holidays.rb
444
446
  - test/integration/test_holidays.rb