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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ee07ba0f1799dc3306a9969c2ad7678cf8e708617324781b355dd16c451e720
4
- data.tar.gz: e8d1c3855fe798e057ac779a9ede168bf20794ed36a84b814f65b0a07a6e868b
3
+ metadata.gz: 1e7ebcd7bc94eea5c90a1b7d45e32a07f2ea1045fa8942ae49cc08cf5a11a13a
4
+ data.tar.gz: 0725e404bbb53b5b5f65986eae32eb562c070f03c2c67a41f6680e952446e2f5
5
5
  SHA512:
6
- metadata.gz: f05dc0636679c910ffa575f4037cf7167f6b1662170e536e9dacf3c2a1f6b213c1a592744062f75dea72543ee409595a975b9154b57dc13c1e30ec05e39f03ca
7
- data.tar.gz: b5ac2c5d2f52c4a6908dcea0c162a199426e9afd285901a96681e0fdce4bd5393fc5d11c67d0d0de649aedfa7b0817d2d85a0b70c55c71f5363a976005e04892
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
- TODO: Write usage instructions here
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BusinessHours
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -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 = DateTime.now)
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.next_day(current_time = DateTime.now)
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 = DateTime.now)
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.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-04 00:00:00.000000000 Z
11
+ date: 2022-09-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Used Calculate Business Hours
14
14
  email: