active_period 6.2.1 → 6.3.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
  SHA256:
3
- metadata.gz: 31de1be46b05886d6be69b936ad0d708e0b5169f57e8c96be53be4073196bbf5
4
- data.tar.gz: 6972b4d8c4178901863d9a2e6d5155ce9c1406fc1895c4d54980756652585ab5
3
+ metadata.gz: b844daa7cc7ef648456cbfca6a0160a4cc6f12da6977066ad8a4a310d78bad2e
4
+ data.tar.gz: 520d626a06a54380df33877babdb6854f338c10908d8b03a644aab2e8416b7e8
5
5
  SHA512:
6
- metadata.gz: deb9549d9a5752cd99b98fa3943d6a1b19f07b505319e99439bcfd9f1b1d716d1424c21fc2f60ac1fc9954e06b96ee3473646a3472deb4a28d8cfb3ad6367ea5
7
- data.tar.gz: ed10625ee2779f305739b4ff1f3295d2d66a8cd21cb8371cbe2cde6d2686eedce85d21e845a9171d837b9db075cd0ffefdc6f27693538d57b25f9972720040aa
6
+ metadata.gz: 63a99d4de2e83d52f0c24e1110ad4e37acbad1d7980ea5b6d4c1084dfaae1a676e05a4850f3bb903e725f8c1ca98d09db9b1a14d102cd9686a844b12ca9f84d3
7
+ data.tar.gz: 11f0c8d57e2995e8a745885bddcc8b268920e65d30309048da2f0aeb9d4faa0cee43225f7686529995c6e919e0da1940f0c40d8b3b3ea93c299bf1662750798e
data/Gemfile.lock CHANGED
@@ -1,26 +1,68 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_period (6.2.0)
5
- activesupport (~> 5)
4
+ active_period (6.3.0)
5
+ activesupport (~> 6, >= 5)
6
6
  i18n (~> 1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (5.2.5)
11
+ activesupport (6.0.0)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 0.7, < 2)
14
14
  minitest (~> 5.1)
15
15
  tzinfo (~> 1.1)
16
- concurrent-ruby (1.1.8)
16
+ zeitwerk (~> 2.1, >= 2.1.8)
17
+ builder (3.2.4)
18
+ concurrent-ruby (1.1.9)
19
+ cucumber (7.0.0)
20
+ builder (~> 3.2, >= 3.2.4)
21
+ cucumber-core (~> 10.0, >= 10.0.1)
22
+ cucumber-create-meta (~> 6.0, >= 6.0.1)
23
+ cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
24
+ cucumber-gherkin (~> 20.0, >= 20.0.1)
25
+ cucumber-html-formatter (~> 16.0, >= 16.0.1)
26
+ cucumber-messages (~> 17.0, >= 17.0.1)
27
+ cucumber-wire (~> 6.0, >= 6.0.1)
28
+ diff-lcs (~> 1.4, >= 1.4.4)
29
+ mime-types (~> 3.3, >= 3.3.1)
30
+ multi_test (~> 0.1, >= 0.1.2)
31
+ sys-uname (~> 1.2, >= 1.2.2)
32
+ cucumber-core (10.0.1)
33
+ cucumber-gherkin (~> 20.0, >= 20.0.1)
34
+ cucumber-messages (~> 17.0, >= 17.0.1)
35
+ cucumber-tag-expressions (~> 3.0, >= 3.0.1)
36
+ cucumber-create-meta (6.0.1)
37
+ cucumber-messages (~> 17.0, >= 17.0.1)
38
+ sys-uname (~> 1.2, >= 1.2.2)
39
+ cucumber-cucumber-expressions (12.1.1)
40
+ cucumber-gherkin (20.0.1)
41
+ cucumber-messages (~> 17.0, >= 17.0.1)
42
+ cucumber-html-formatter (16.0.1)
43
+ cucumber-messages (~> 17.0, >= 17.0.1)
44
+ cucumber-messages (17.0.1)
45
+ cucumber-tag-expressions (3.0.1)
46
+ cucumber-wire (6.0.1)
47
+ cucumber-core (~> 10.0, >= 10.0.1)
48
+ cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
49
+ cucumber-messages (~> 17.0, >= 17.0.1)
50
+ diff-lcs (1.4.4)
51
+ ffi (1.15.3)
17
52
  i18n (1.8.10)
18
53
  concurrent-ruby (~> 1.0)
54
+ mime-types (3.3.1)
55
+ mime-types-data (~> 3.2015)
56
+ mime-types-data (3.2021.0704)
19
57
  minitest (5.14.4)
58
+ multi_test (0.1.2)
20
59
  rake (10.5.0)
60
+ sys-uname (1.2.2)
61
+ ffi (~> 1.1)
21
62
  thread_safe (0.3.6)
22
63
  tzinfo (1.2.9)
23
64
  thread_safe (~> 0.1)
65
+ zeitwerk (2.4.2)
24
66
 
25
67
  PLATFORMS
26
68
  ruby
@@ -28,6 +70,7 @@ PLATFORMS
28
70
  DEPENDENCIES
29
71
  active_period!
30
72
  bundler (~> 2.0)
73
+ cucumber
31
74
  rake (~> 10.0)
32
75
 
33
76
  BUNDLED WITH
data/README.md CHANGED
@@ -51,6 +51,9 @@ Period.new(..Time.now).months.reverse_each # => Enumerable
51
51
  # Write a date for me (I18n supported)
52
52
  Period.new('20/01/2017'...'20/01/2021').to_s
53
53
  => "From the 20 January 2017 to the 20 January 2021 excluded"
54
+
55
+ # Get all US holidays in the next week (see holiday's section below)
56
+ Period.next_week.holidays(:us)
54
57
  ```
55
58
 
56
59
  ## Detailed view
@@ -311,7 +314,7 @@ For a FreePeriod or if you need to print the start and the end of your period di
311
314
  ## The tricky case of Weeks
312
315
 
313
316
  Weeks are implemented following the [ISO 8601](https://en.wikipedia.org/wiki/ISO_week_date)
314
- So `Period.this_month.weeks.first` doesn't necessarily include the first days of the month
317
+ So `Period.this_month.weeks.first` doesn't necessarily include the first days of the month
315
318
  Also a **StandardPeriod** and a **FreePeriod** covering the same range of time, may not includes the same `Weeks`
316
319
 
317
320
  ## TimeZone
@@ -333,21 +336,22 @@ require 'holidays'
333
336
  # Get all worldwide holidays in the current month
334
337
  Period.this_month.holidays
335
338
 
336
- # Get all US holidays in the current month
337
- Period.this_month.holidays(:us)
339
+ # Get all US holidays in the next week
340
+ Period.next_week.holidays(:us)
338
341
 
339
- # Get all US and CA holidays in the current month
340
- Period.this_month.holidays(:us, :ca)
342
+ # Get all US and CA holidays in the prev quarter
343
+ Period.prev_quarter.holidays(:us, :ca)
341
344
 
342
345
  # 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
346
+ holiday = (Time.now..).to_period.holidays(:fr).first
347
+ # return the next holiday with same options as the original `.holidays` collection
345
348
  holiday.next
346
- # return the previous holiday within the same options of the original `.holidays` collection
349
+ # return the previous holiday with same options as the original `.holidays` collection
347
350
  holiday.prev
348
351
  ```
349
352
 
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`
353
+ :warning: If you call a `holidays` related method without the [gem holidays](https://github.com/holidays/holidays) in your project
354
+ You will raise a `RuntimeError`
351
355
  ```ruby
352
356
  Period.this_month.holidays
353
357
  #=> RuntimeError (The gem "holidays" is needed for this feature to work)
@@ -356,7 +360,6 @@ Period.this_month.holidays
356
360
  ## Planned updates
357
361
 
358
362
  - [ ] ActiveRecord Serializer (maybe)
359
- - [ ] Holidays support (gem Holidays) -> COMING SOON
360
363
 
361
364
  ## Bug reports
362
365
 
@@ -37,8 +37,11 @@ Gem::Specification.new do |spec|
37
37
  spec.require_paths = %w[lib config]
38
38
 
39
39
  spec.required_ruby_version = '>= 2.7'
40
- spec.add_runtime_dependency 'activesupport', '~> 5'
40
+
41
+ spec.add_runtime_dependency 'activesupport', '>= 5', '~> 6'
41
42
  spec.add_runtime_dependency 'i18n', '~> 1'
43
+
42
44
  spec.add_development_dependency 'bundler', '~> 2.0'
43
45
  spec.add_development_dependency 'rake', '~> 10.0'
46
+ spec.add_development_dependency 'cucumber'
44
47
  end
@@ -1,5 +1,5 @@
1
1
  module ActivePeriod
2
2
 
3
- VERSION = '6.2.1'.freeze
3
+ VERSION = '6.3.1'.freeze
4
4
 
5
5
  end
data/lib/active_period.rb CHANGED
@@ -23,6 +23,8 @@ require_relative 'active_period/year.rb'
23
23
  require_relative 'active_period/holiday.rb'
24
24
  require_relative 'period.rb'
25
25
 
26
+ # TODO find a way to cleanup this require_relative mess ><
27
+
26
28
  module ActivePeriod
27
29
 
28
30
  end
data/lib/period.rb CHANGED
@@ -1,34 +1,43 @@
1
+ # This module is intended to hide the complexity of ActivePeriod
2
+ # And permit the user to write less and doing more
1
3
  module Period
4
+
5
+ # Shorthand to ActivePeriod::FreePeriod.new
2
6
  def self.new(*args)
3
7
  ActivePeriod::FreePeriod.new(*args)
4
8
  end
5
9
 
10
+ # Shorthand ActivePeriod::FreePeriod.new(range, allow_beginless: false, allow_endless: false)
6
11
  def self.bounded(range)
7
12
  ActivePeriod::FreePeriod.new(range, allow_beginless: false, allow_endless: false)
8
13
  end
9
14
 
15
+ # env_time provide a Fallback if the project dont specify any Time.zone
10
16
  def self.env_time
11
17
  (Time.zone || Time)
12
18
  end
13
19
 
20
+ # Dynamic definition of `.(last|this|next)_(day|week|month|quarter|year)`
21
+ # and `.yesterday` `.today` `.tomorrow`
22
+ # TODO implement (last|next)_holiday
14
23
  class << self
15
- %i[day week month quarter year].each do |period|
16
- define_method "last_#{period}" do
17
- date = env_time.now.send(period == :day ? 'yesterday' : "last_#{period}")
18
- Object.const_get("ActivePeriod::#{period.capitalize}").new(date)
24
+ %i[day week month quarter year].each do |standard_period|
25
+ define_method "last_#{standard_period}" do
26
+ date = env_time.now.send(standard_period == :day ? 'yesterday' : "last_#{standard_period}")
27
+ Object.const_get("ActivePeriod::#{standard_period.capitalize}").new(date)
19
28
  end
20
29
 
21
- define_method "this_#{period}" do
22
- Object.const_get("ActivePeriod::#{period.capitalize}").new(env_time.now)
30
+ define_method "this_#{standard_period}" do
31
+ Object.const_get("ActivePeriod::#{standard_period.capitalize}").new(env_time.now)
23
32
  end
24
33
 
25
- define_method "next_#{period}" do
26
- date = env_time.now.send(period == :day ? 'tomorrow' : "next_#{period}")
27
- Object.const_get("ActivePeriod::#{period.capitalize}").new(date)
34
+ define_method "next_#{standard_period}" do
35
+ date = env_time.now.send(standard_period == :day ? 'tomorrow' : "next_#{standard_period}")
36
+ Object.const_get("ActivePeriod::#{standard_period.capitalize}").new(date)
28
37
  end
29
38
 
30
- define_method period.to_s do |range|
31
- Object.const_get("ActivePeriod::#{period.capitalize}").new(range)
39
+ define_method standard_period.to_s do |range|
40
+ Object.const_get("ActivePeriod::#{standard_period.capitalize}").new(range)
32
41
  end
33
42
  end
34
43
 
@@ -36,6 +45,10 @@ module Period
36
45
  alias tomorrow next_day
37
46
  alias today this_day
38
47
 
48
+ # Experimental non-documented feature
49
+ # Inpired form ActiveRecord dynamic find_by_x like User.find_by_name
50
+ # Example: Period.last_3_weeks_from_now == Period.mew(2.weeks.ago.beginning_of_week..Time.now.end_of_week)
51
+ # Note : Maybe it should return a collection of StandardPeriod
39
52
  def method_missing(method_name, *arguments, &block)
40
53
  super unless method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/)
41
54
  last_next, count, klass = method_name.to_s.split('_')
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_period
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.1
4
+ version: 6.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - billau_l
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-03 00:00:00.000000000 Z
11
+ date: 2021-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5'
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '5'
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: i18n
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +72,20 @@ dependencies:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
74
  version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: cucumber
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
69
89
  description:
70
90
  email:
71
91
  executables: []