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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +9 -0
- data/lib/holidays.rb +1 -1
- data/lib/holidays/definition/repository/cache.rb +2 -2
- data/lib/holidays/version.rb +1 -1
- data/test/integration/test_holidays.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d40a353408c8718766db07f2d93af0919ee634
|
4
|
+
data.tar.gz: 7c048aa0dbd4d88aebe9de8911813a335f518c7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 272e786897df3caf4fbdf2031cfc920493705f61f6d411547d5714f15e613756d50f37a514abedec0e27902c510d4d37ae3313c60e69ccee89998db657c069c2
|
7
|
+
data.tar.gz: d24f51fa3bc7f7668bf67956f3a2aad2ab213f235ea8ac716f8cd08910a82d4cb684f205d9b328f23b602647cbed1215eb5371ab19a67daa1be71104fe3bd6cd
|
data/CHANGELOG.md
CHANGED
@@ -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!
|
data/lib/holidays.rb
CHANGED
@@ -6,14 +6,14 @@ module Holidays
|
|
6
6
|
reset!
|
7
7
|
end
|
8
8
|
|
9
|
-
def cache_between(start_date, end_date, cache_data,
|
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,
|
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|
|
data/lib/holidays/version.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2016-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|