roxbury 0.2.1 → 0.2.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: '083b94bc5b909ea14a3607950f68fc1cdf22c6319bec0dd97fa8bc125ce8de54'
4
- data.tar.gz: 464e95eda05d38625f90b7ea63ff38c4554de4045a58cb60e3959337427867e6
3
+ metadata.gz: 9be014146f5e1168ed8b68ee666b2ce04ce516408b48109c1ec5a6353a893cf5
4
+ data.tar.gz: 97557e9b8524dbdee5ebeb99c8aed3f713513772070d35b99aa4ec86ff057634
5
5
  SHA512:
6
- metadata.gz: e45ddec1a5f4a24a66e171c9d8bff69018ab39a1c67759163f5b352c68be6271e86a424467b343a71ce7f1d14bda57f9c02a41c055cd84eed0ee1c92f233a05f
7
- data.tar.gz: bdb32f0528ba2d0f2d1408652fa61795bf07935cf8c1b0796495f2720b319cd74aa00a6e1441f8839943c6ada28629ae2431a62cefb9a844a301b915ab1029f6
6
+ metadata.gz: c56999bb0d6a4a608bb197c808bf45a68f86e3666137d06fe9316ef08b403cbc4f0a217c2de0482639de477db230a85346d1d8b8f2a351832bc4d7a35eac7141
7
+ data.tar.gz: 17ae768de1de2dd6a15299625a995f08cef862fa8b9b4b847f56cc3a92233c935d6b871fff22eb5627c7940de344f0695a00b894deecf6eb71e471851cc8e42e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roxbury (0.2.1)
4
+ roxbury (0.2.2)
5
5
  activesupport (>= 4.2)
6
6
 
7
7
  GEM
@@ -86,6 +86,20 @@ module Roxbury
86
86
  end
87
87
  end
88
88
 
89
+ # Snaps the date to the end of the previous business day, unless it is already within the working hours of a business day.
90
+ #
91
+ # @param date [Date, Time]
92
+ def roll_backward date
93
+ bday = business_day(date)
94
+ if bday.include?(date)
95
+ date
96
+ elsif bday.ends_before?(date)
97
+ bday.at_end
98
+ else
99
+ roll_backward(date.is_a?(Date) ? date.yesterday : date.yesterday.end_of_day)
100
+ end
101
+ end
102
+
89
103
  # If a Date is given, returns then next business day.
90
104
  # Otherwise if a Time is given, snaps the date to the beginning of the next business day.
91
105
  def next_working_day date
@@ -99,6 +113,19 @@ module Roxbury
99
113
  end
100
114
  end
101
115
 
116
+ # If a Date is given, returns then prev business day.
117
+ # Otherwise if a Time is given, snaps the date to the beginning of the prev business day.
118
+ def prev_working_day date
119
+ case date
120
+ when Time
121
+ roll_backward date.yesterday.end_of_day
122
+ when Date
123
+ roll_backward date.yesterday
124
+ else
125
+ raise ArgumentError, 'only Date or Time instances are allowed'
126
+ end
127
+ end
128
+
102
129
  def working_hours_percentage date
103
130
  business_day(date).number_of_working_hours * 1.0 / max_working_hours_in_a_day
104
131
  end
@@ -22,6 +22,10 @@ module Roxbury
22
22
  same_day?(timestamp) && @working_hours.starts_after?(timestamp)
23
23
  end
24
24
 
25
+ def ends_before? timestamp
26
+ same_day?(timestamp) && @working_hours.ends_before?(timestamp)
27
+ end
28
+
25
29
  def at_beginning
26
30
  @working_hours.at_beginning @date
27
31
  end
@@ -13,6 +13,10 @@ module Roxbury
13
13
  false
14
14
  end
15
15
 
16
+ def ends_before? _timestamp
17
+ false
18
+ end
19
+
16
20
  def non_working?
17
21
  true
18
22
  end
@@ -1,3 +1,3 @@
1
1
  module Roxbury
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -35,6 +35,10 @@ module Roxbury
35
35
  timestamp < at_beginning(timestamp)
36
36
  end
37
37
 
38
+ def ends_before? timestamp
39
+ timestamp > at_end(timestamp)
40
+ end
41
+
38
42
  def at_beginning timestamp
39
43
  timestamp.change(hour: begins_at, min: 0, sec: 0)
40
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roxbury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Nicolau