roxbury 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/roxbury/business_calendar.rb +27 -0
- data/lib/roxbury/business_day.rb +4 -0
- data/lib/roxbury/empty_working_hours.rb +4 -0
- data/lib/roxbury/version.rb +1 -1
- data/lib/roxbury/working_hours.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9be014146f5e1168ed8b68ee666b2ce04ce516408b48109c1ec5a6353a893cf5
|
4
|
+
data.tar.gz: 97557e9b8524dbdee5ebeb99c8aed3f713513772070d35b99aa4ec86ff057634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56999bb0d6a4a608bb197c808bf45a68f86e3666137d06fe9316ef08b403cbc4f0a217c2de0482639de477db230a85346d1d8b8f2a351832bc4d7a35eac7141
|
7
|
+
data.tar.gz: 17ae768de1de2dd6a15299625a995f08cef862fa8b9b4b847f56cc3a92233c935d6b871fff22eb5627c7940de344f0695a00b894deecf6eb71e471851cc8e42e
|
data/Gemfile.lock
CHANGED
@@ -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
|
data/lib/roxbury/business_day.rb
CHANGED
@@ -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
|
data/lib/roxbury/version.rb
CHANGED