business-period 0.1.2 → 0.1.3
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 +1 -1
- data/lib/business_period/base.rb +4 -3
- data/lib/business_period/days.rb +17 -5
- data/lib/business_period/version.rb +1 -1
- 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: 6098b1a6ef4926e03bce624585c037eaf04cbc67
|
|
4
|
+
data.tar.gz: 4e3844c7a1cfae8573cb5afe08fd6aa24f3fbc39
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10251873c3359a732d0bf338a61ce91ab254ab0bd3c71985b849f1b9e97ce57b6adee8257cf850951065a7f24ea8957ca2a493d2215599d97b2d60fb68b5639c
|
|
7
|
+
data.tar.gz: 61c2faa61df87564ea89311937158cb7515f70f73a31d05d2138314946369996bc3727fd8d5cc0b4465bd6e3073763dc500631bc9de3cc52ab49988a0d50500b
|
data/Gemfile.lock
CHANGED
data/lib/business_period/base.rb
CHANGED
|
@@ -6,11 +6,12 @@ module BusinessPeriod
|
|
|
6
6
|
@config ||= Config
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def calculate_period(to_date)
|
|
9
|
+
def calculate_period(to_date, options = nil)
|
|
10
10
|
magic_number = 15 - config.work_days.size
|
|
11
11
|
days_to_add = days_to_seconds(to_date * magic_number)
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
start_date = options[:primary_day] || Time.now
|
|
13
|
+
finish = start_date + days_to_add
|
|
14
|
+
start_date.to_date..finish.to_date
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def holidays
|
data/lib/business_period/days.rb
CHANGED
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
module BusinessPeriod
|
|
4
4
|
class Days < Base
|
|
5
|
-
def self.call(from_date:, to_date:)
|
|
6
|
-
new.perform(from_date, to_date)
|
|
5
|
+
def self.call(from_date:, to_date:, options: {})
|
|
6
|
+
new.perform(from_date, to_date, options)
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def perform(from_date, to_date)
|
|
9
|
+
def perform(from_date, to_date, options)
|
|
10
10
|
@from_date = from_date
|
|
11
11
|
@to_date = to_date
|
|
12
|
+
@options = options
|
|
12
13
|
|
|
13
14
|
return [] unless valid_params
|
|
14
15
|
|
|
15
|
-
period = calculate_period(@to_date)
|
|
16
|
+
period = calculate_period(@to_date, @options)
|
|
16
17
|
days = business_days(period)
|
|
17
18
|
result = extract_holidays(days).compact
|
|
18
19
|
|
|
@@ -25,11 +26,22 @@ module BusinessPeriod
|
|
|
25
26
|
private
|
|
26
27
|
|
|
27
28
|
def valid_params
|
|
28
|
-
|
|
29
|
+
valid_options &&
|
|
30
|
+
@from_date.is_a?(Integer) && @to_date.is_a?(Integer) &&
|
|
29
31
|
@from_date >= 0 && @to_date >= 0 &&
|
|
30
32
|
(@from_date <= @to_date)
|
|
31
33
|
end
|
|
32
34
|
|
|
35
|
+
def valid_options
|
|
36
|
+
@options ? primary_day_present? : true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def primary_day_present?
|
|
40
|
+
return unless @options.is_a?(Hash)
|
|
41
|
+
|
|
42
|
+
@options[:primary_day] ? (@options[:primary_day].methods.include? :strftime) : true
|
|
43
|
+
end
|
|
44
|
+
|
|
33
45
|
def extract_holidays(days)
|
|
34
46
|
days.map.with_index do |day, idx|
|
|
35
47
|
next unless holidays[day[:day].month]
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: business-period
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- matas
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-12-
|
|
11
|
+
date: 2018-12-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|