holidays 5.2.0 → 5.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6d31623329597545a952074f25ebce282d0fe5e
4
- data.tar.gz: aeac59f19f9daf945edcf3570edbfe655a582c75
3
+ metadata.gz: 48d40a353408c8718766db07f2d93af0919ee634
4
+ data.tar.gz: 7c048aa0dbd4d88aebe9de8911813a335f518c7a
5
5
  SHA512:
6
- metadata.gz: 7dbddcad5a4c32ec56bd0dee354fe6323752c8205f147a6b935d9723050eb590df5c15c18caaea97ec812617f850b181581046c5d06882552b969d51458b6588
7
- data.tar.gz: 73ada22bfbca45a7adafa80ecbaeb44ba9c330b6eab55b6edbe5ccaadaee9ef0edf351834e23bf7cf3f5d4caebd716299348f917275db01b0431ddea79968f74
6
+ metadata.gz: 272e786897df3caf4fbdf2031cfc920493705f61f6d411547d5714f15e613756d50f37a514abedec0e27902c510d4d37ae3313c60e69ccee89998db657c069c2
7
+ data.tar.gz: d24f51fa3bc7f7668bf67956f3a2aad2ab213f235ea8ac716f8cd08910a82d4cb684f205d9b328f23b602647cbed1215eb5371ab19a67daa1be71104fe3bd6cd
@@ -1,5 +1,10 @@
1
1
  # Ruby Holidays Gem CHANGELOG
2
2
 
3
+ ## 5.2.1
4
+
5
+ * Fix caching (i.e. calls to `cache_between`) to...you know, actually cache correctly and give
6
+ performance improvements. Thanks to https://github.com/AnotherJoSmith for the fix!
7
+
3
8
  ## 5.2.0
4
9
 
5
10
  * Point to latest (v1.2.0 of definitions)
data/README.md CHANGED
@@ -153,6 +153,15 @@ Or find end of month for given date (requires 'Time' extensions as well):
153
153
  d.end_of_month
154
154
  => #<Date: 2016-08-31 ((2457632j,0s,0n),+0s,2299161j)>
155
155
 
156
+
157
+ ### Caching Holiday Lookups
158
+
159
+ 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):
160
+
161
+ Holidays.cache_between(Time.now, 2.years.from_now, :ca, :us, :observed)
162
+
163
+ Holidays for the regions specified within the dates specified will be pre-calculated and stored in-memory. Future lookups will be much faster.
164
+
156
165
  ### How to contribute
157
166
 
158
167
  See our [contribution guidelines](CONTRIBUTING.md) for information on how to help out!
@@ -29,7 +29,7 @@ module Holidays
29
29
  end
30
30
 
31
31
  def on(date, *options)
32
- between(date, date, options)
32
+ between(date, date, *options)
33
33
  end
34
34
 
35
35
  def between(start_date, end_date, *options)
@@ -6,14 +6,14 @@ module Holidays
6
6
  reset!
7
7
  end
8
8
 
9
- def cache_between(start_date, end_date, cache_data, *options)
9
+ def cache_between(start_date, end_date, cache_data, options)
10
10
  raise ArgumentError unless cache_data
11
11
 
12
12
  @cache_range[options] = start_date..end_date
13
13
  @cache[options] = cache_data
14
14
  end
15
15
 
16
- def find(start_date, end_date, *options)
16
+ def find(start_date, end_date, options)
17
17
  if range = @cache_range[options]
18
18
  if range.begin <= start_date && range.end >= end_date
19
19
  return @cache[options].select do |holiday|
@@ -1,3 +1,3 @@
1
1
  module Holidays
2
- VERSION = '5.2.0'
2
+ VERSION = '5.2.1'
3
3
  end
@@ -269,17 +269,17 @@ class HolidaysTests < Test::Unit::TestCase
269
269
  cache_data = Holidays.between(start_date, end_date, :ca, :informal)
270
270
  options = [:ca, :informal]
271
271
 
272
- Holidays::Factory::Definition.cache_repository.expects(:cache_between).with(start_date, end_date, cache_data, options)
273
-
274
272
  Holidays.cache_between(Date.civil(2008,3,21), Date.civil(2008,3,25), :ca, :informal)
275
273
 
276
- # Test that cache has been set and it returns the same as before
277
- assert_equal 1, Holidays.on(Date.civil(2008, 3, 21), :ca, :informal).length
278
- assert_equal 1, Holidays.on(Date.civil(2008, 3, 24), :ca, :informal).length
279
-
280
274
  # Test that correct results are returned outside the cache range, and with no caching
281
275
  assert_equal 1, Holidays.on(Date.civil(2035,1,1), :ca, :informal).length
282
276
  assert_equal 1, Holidays.on(Date.civil(2035,1,1), :us).length
277
+
278
+ Holidays::Factory::Finder.expects(:between).never # Make sure cache is hit for two next call
279
+
280
+ # Test that cache has been set and it returns the same as before
281
+ assert_equal 1, Holidays.on(Date.civil(2008, 3, 21), :ca, :informal).length
282
+ assert_equal 1, Holidays.on(Date.civil(2008, 3, 24), :ca, :informal).length
283
283
  end
284
284
 
285
285
  def test_load_all
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.2.0
4
+ version: 5.2.1
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-11-23 00:00:00.000000000 Z
12
+ date: 2016-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler