active_period 6.1.1 → 6.2.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 +4 -4
- data/Gemfile.lock +10 -12
- data/README.md +37 -4
- data/lib/active_period/collection/free_period.rb +1 -1
- data/lib/active_period/collection/holiday_period.rb +2 -2
- data/lib/active_period/collection/standard_period.rb +2 -2
- data/lib/active_period/holiday.rb +10 -4
- data/lib/active_period/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dba2a2ea208d8904f845e463f8f82f96590dce4f2ad10557a77f30bc9065380d
|
4
|
+
data.tar.gz: 869c18ddc605ccc8fa4cd23da17bfad196e4cdc92de3c1fed5f378d66c2351cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0287446e67fa3f801b70fcfe6fbf1190a9ac2f3957dc3ffd3cb499046e9f3ae8910ca01d5aa6142a0816012bc0db8505f93fccf432d7e1b7f4b624edcd112e2
|
7
|
+
data.tar.gz: aa43b0db9103fb16e82b84ea29c62783d100b83b742f89393f2aaca73348da6d0aaeef6ee9623252e55e7f7dd4c721bcdba0fdaff9e74d11cbe50c50d7ff356a
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_period (6.
|
5
|
-
activesupport (~>
|
4
|
+
active_period (6.2.0)
|
5
|
+
activesupport (~> 5)
|
6
6
|
i18n (~> 1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (
|
11
|
+
activesupport (5.2.5)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (>=
|
14
|
-
minitest (
|
15
|
-
tzinfo (~>
|
16
|
-
zeitwerk (~> 2.3)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
17
16
|
concurrent-ruby (1.1.8)
|
18
17
|
i18n (1.8.10)
|
19
18
|
concurrent-ruby (~> 1.0)
|
20
19
|
minitest (5.14.4)
|
21
20
|
rake (10.5.0)
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
thread_safe (0.3.6)
|
22
|
+
tzinfo (1.2.9)
|
23
|
+
thread_safe (~> 0.1)
|
25
24
|
|
26
25
|
PLATFORMS
|
27
26
|
ruby
|
28
|
-
x86_64-darwin-19
|
29
27
|
|
30
28
|
DEPENDENCIES
|
31
29
|
active_period!
|
@@ -33,4 +31,4 @@ DEPENDENCIES
|
|
33
31
|
rake (~> 10.0)
|
34
32
|
|
35
33
|
BUNDLED WITH
|
36
|
-
2.2
|
34
|
+
2.1.2
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# ActivePeriod
|
2
|
-
[](https://badge.fury.io/rb/active_period)
|
3
|
-
[](https://codeclimate.com/github/billaul/period)
|
4
|
-
[](http://inch-ci.org/github/billaul/period)
|
1
|
+
# ActivePeriod
|
2
|
+
[](https://badge.fury.io/rb/active_period)
|
3
|
+
[](https://codeclimate.com/github/billaul/period)
|
4
|
+
[](http://inch-ci.org/github/billaul/period)
|
5
5
|
[](http://rubygems.org/gems/active_period)
|
6
6
|
|
7
7
|
ActivePeriod aims to simplify Time-range manipulation.
|
@@ -320,6 +320,39 @@ Time zone are supported
|
|
320
320
|
If you change the global `Time.zone` of your app
|
321
321
|
If your Period [begin in a time zone and end in another](https://en.wikipedia.org/wiki/Daylight_saving_time), you have nothing to do
|
322
322
|
|
323
|
+
## Holidays
|
324
|
+
|
325
|
+
`ActivePeriod` include an optional support of the [gem holidays](https://github.com/holidays/holidays)
|
326
|
+
If your project include this gem you can use the power of `.holidays` and `.holiday?`
|
327
|
+
|
328
|
+
`.holiday?` and `.holidays` take the same params as `Holidays.on` except the first one
|
329
|
+
`Holidays.on(Date.civil(2008, 4, 25), :au)` become `Period.day('24/04/2008').holidays(:au)` or `Period.day('24/04/2008').holiday?(:au)`
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
require 'holidays'
|
333
|
+
# Get all worldwide holidays in the current month
|
334
|
+
Period.this_month.holidays
|
335
|
+
|
336
|
+
# Get all US holidays in the current month
|
337
|
+
Period.this_month.holidays(:us)
|
338
|
+
|
339
|
+
# Get all US and CA holidays in the current month
|
340
|
+
Period.this_month.holidays(:us, :ca)
|
341
|
+
|
342
|
+
# First up coming `FR` holiday
|
343
|
+
holiday = Period.new(Time.now..).holidays(:fr).first
|
344
|
+
# return the next holiday within the same options of the original `.holidays` collection
|
345
|
+
holiday.next
|
346
|
+
# return the previous holiday within the same options of the original `.holidays` collection
|
347
|
+
holiday.prev
|
348
|
+
```
|
349
|
+
|
350
|
+
:warning: If you call a `holidays` related method without the [gem holidays](https://github.com/holidays/holidays) in your project you will raise a `RuntimeError`
|
351
|
+
```ruby
|
352
|
+
Period.this_month.holidays
|
353
|
+
#=> RuntimeError (The gem "holidays" is needed for this feature to work)
|
354
|
+
```
|
355
|
+
|
323
356
|
## Planned updates
|
324
357
|
|
325
358
|
- [ ] ActiveRecord Serializer (maybe)
|
@@ -23,7 +23,7 @@ module ActivePeriod
|
|
23
23
|
raise RangeError.new "cannot get the last element of endless range" if period.endless?
|
24
24
|
|
25
25
|
Enumerator.new do |yielder|
|
26
|
-
current = klass.new(period.
|
26
|
+
current = klass.new(period.calculated_end)
|
27
27
|
while period.begin.nil? || period.include?(current.begin) || period.include?(current.calculated_end)
|
28
28
|
yielder << current
|
29
29
|
current = current.prev
|
@@ -19,7 +19,7 @@ module ActivePeriod
|
|
19
19
|
days = period.try(:days) || [period]
|
20
20
|
days.each do |day|
|
21
21
|
Holidays.on(day.begin.to_date, *options).each do |hash|
|
22
|
-
yielder << ActivePeriod::Holiday.new(**hash)
|
22
|
+
yielder << ActivePeriod::Holiday.new(**hash, options: @options)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
# At the end (if there is one) the Collection will be return
|
@@ -32,7 +32,7 @@ module ActivePeriod
|
|
32
32
|
days = period.try(:days) || [period]
|
33
33
|
days.reverse_each do |day|
|
34
34
|
Holidays.on(day.begin.to_date, *options).each do |hash|
|
35
|
-
yielder << ActivePeriod::Holiday.new(**hash)
|
35
|
+
yielder << ActivePeriod::Holiday.new(**hash, options: @options)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
# At the end (if there is one) the Collection will be return
|
@@ -8,7 +8,7 @@ module ActivePeriod
|
|
8
8
|
def enumerator
|
9
9
|
Enumerator.new do |yielder|
|
10
10
|
current = klass.new(period.begin)
|
11
|
-
while current.
|
11
|
+
while current.calculated_end <= period.calculated_end || period.include?(current)
|
12
12
|
yielder << current if period.include?(current)
|
13
13
|
current = current.next
|
14
14
|
end
|
@@ -19,7 +19,7 @@ module ActivePeriod
|
|
19
19
|
|
20
20
|
def reverse_enumerator
|
21
21
|
Enumerator.new do |yielder|
|
22
|
-
current = klass.new(period.
|
22
|
+
current = klass.new(period.calculated_end)
|
23
23
|
while current.begin <= period.begin || period.include?(current)
|
24
24
|
yielder << current if period.include?(current)
|
25
25
|
current = current.prev
|
@@ -10,27 +10,32 @@ class ActivePeriod::Holiday < ActivePeriod::Day
|
|
10
10
|
# @return [<Symbol>] regions where the Holiday occure
|
11
11
|
attr_reader :regions
|
12
12
|
|
13
|
+
# @!attribute [r] options
|
14
|
+
# @return [Array] The array of options for Holidays.on
|
15
|
+
attr_reader :options
|
13
16
|
|
14
17
|
# @param date [...] A valid param for Period.day(...)
|
15
18
|
# @param name [String] The name of the Holiday
|
16
19
|
# @param regions [<Symbol>] region where the Holiday occure
|
20
|
+
# @param options [...] The array of options for Holidays.on
|
17
21
|
# @return [Type] ActivePeriod::Holiday
|
18
22
|
# @raise RuntimeError if the gem "holidays" is not included
|
19
|
-
def initialize(date: , name:, regions: )
|
23
|
+
def initialize(date: , name:, regions: , options: )
|
20
24
|
raise I18n.t(:gem_require, scope: %i[active_period holiday_period]) unless Object.const_defined?('Holidays')
|
21
25
|
super(date)
|
22
26
|
|
23
27
|
@name = name
|
24
28
|
@regions = regions
|
29
|
+
@options = options
|
25
30
|
end
|
26
31
|
|
27
32
|
def next
|
28
|
-
|
33
|
+
Period.new(beginning+1.day..).holidays(options).first
|
29
34
|
end
|
30
35
|
alias succ next
|
31
36
|
|
32
37
|
def prev
|
33
|
-
|
38
|
+
Period.new(...ending).holidays(options).last
|
34
39
|
end
|
35
40
|
|
36
41
|
def _period
|
@@ -62,7 +67,7 @@ class ActivePeriod::Holiday < ActivePeriod::Day
|
|
62
67
|
end
|
63
68
|
|
64
69
|
def i18n(&block)
|
65
|
-
return yield(
|
70
|
+
return yield(self) if block.present?
|
66
71
|
|
67
72
|
I18n.t(:default_format,
|
68
73
|
scope: i18n_scope,
|
@@ -72,6 +77,7 @@ class ActivePeriod::Holiday < ActivePeriod::Day
|
|
72
77
|
month: I18n.l(from, format: '%B').capitalize,
|
73
78
|
year: from.year)
|
74
79
|
end
|
80
|
+
alias inspect i18n
|
75
81
|
|
76
82
|
def i18n_scope
|
77
83
|
[:active_period, :holiday_period]
|