calculate_time 0.1.1 → 0.1.2
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/README.md +18 -1
- data/lib/business_hours/version.rb +1 -1
- data/lib/business_hours.rb +16 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e7ebcd7bc94eea5c90a1b7d45e32a07f2ea1045fa8942ae49cc08cf5a11a13a
|
4
|
+
data.tar.gz: 0725e404bbb53b5b5f65986eae32eb562c070f03c2c67a41f6680e952446e2f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f1693d830e0459232fee8991b044b01563a702454bdef9054b20dfd3c239ce74266852740422d12524703e57c7f6426f3ec3be2688894480c1244bc9fb5b33
|
7
|
+
data.tar.gz: 33cd3ce5a209f376f38896b932a461921df633f9eb0fd39da3bc401129b5376284350c81299aafa450f191419760d9362a692a28d61e633daf426e9c5033c54d
|
data/README.md
CHANGED
@@ -22,7 +22,24 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Finding Business Day
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
$ BusinessHours.next_day # Next Business Day
|
29
|
+
$ BusinessHours.previous_day # Previous Business Day
|
30
|
+
```
|
31
|
+
|
32
|
+
Check Business Day
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
$ BusinessHours.is? # true if business_day
|
36
|
+
```
|
37
|
+
|
38
|
+
Add n Business Days
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
$ BusinessHours.add_days(n, DateTime.now) # date is optional default it takes today's date
|
42
|
+
```
|
26
43
|
|
27
44
|
## Development
|
28
45
|
|
data/lib/business_hours.rb
CHANGED
@@ -10,20 +10,25 @@ module BusinessHours
|
|
10
10
|
END_TIME = 17
|
11
11
|
BUSINESS_DAYS = (1..5)
|
12
12
|
BUSINESS_HOURS = (9..17)
|
13
|
+
CURRENT_TIME = DateTime.now
|
13
14
|
|
14
15
|
def self.greetings(name)
|
15
16
|
puts "Hi #{name}!"
|
16
17
|
end
|
17
18
|
|
18
|
-
def self.is?(current_time =
|
19
|
+
def self.is?(current_time = CURRENT_TIME)
|
19
20
|
BUSINESS_DAYS.include?(current_time.wday) && BUSINESS_HOURS.include?(current_time.hour)
|
20
21
|
end
|
21
22
|
|
22
|
-
def self.
|
23
|
+
def self.add_days(days, current_time = CURRENT_TIME)
|
24
|
+
add_business_days(days, current_time.to_date) + START_TIME*60**2
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.next_day(current_time = CURRENT_TIME)
|
23
28
|
(current_time.to_date + count_day(current_time.wday)).to_time + START_TIME*60**2
|
24
29
|
end
|
25
30
|
|
26
|
-
def self.previous_day(current_time =
|
31
|
+
def self.previous_day(current_time = CURRENT_TIME)
|
27
32
|
(current_time.to_date - count_day(current_time.wday, true)).to_time + START_TIME*60**2
|
28
33
|
end
|
29
34
|
|
@@ -37,4 +42,12 @@ module BusinessHours
|
|
37
42
|
previous ? 1 : 2
|
38
43
|
end
|
39
44
|
end
|
45
|
+
|
46
|
+
def self.add_business_days(days, date)
|
47
|
+
days.times.each do |day|
|
48
|
+
date = is?(date.to_time) ? date.next_day : date + count_day(date.wday)
|
49
|
+
end
|
50
|
+
date.to_time
|
51
|
+
end
|
52
|
+
|
40
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calculate_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chitradevi36
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Used Calculate Business Hours
|
14
14
|
email:
|