opening_hours 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/opening_hours.rb CHANGED
@@ -99,16 +99,17 @@ class OpeningHours
99
99
  break_hours = get_break_hours(today)
100
100
  # here is possible to use strict greater operator if you want to stop on edge of previous business day.
101
101
  # see "BusinessHours schedule without exceptions should flip the edge" spec
102
-
103
- if open_hours.open + job_duration >= break_hours.open
104
- job_duration += break_hours_duration
105
- end
106
-
107
- while job_duration >= (open_hours.duration - break_hours_duration)
108
- job_duration -= open_hours.duration + break_hours_duration
102
+
103
+ while job_duration >= open_hours.duration
104
+ job_duration -= open_hours.duration
109
105
 
110
106
  today = today.next
111
107
  open_hours = get_open_hours(today)
108
+ break_hours = get_break_hours(today)
109
+ end
110
+
111
+ if (open_hours.open + job_duration).between?(break_hours.open, break_hours.close)
112
+ job_duration += break_hours_duration
112
113
  end
113
114
 
114
115
  Time.zone.local(today.year, today.month, today.day, *TimeUtils::time_from_midnight(open_hours.open + job_duration)).to_formatted_s(:rfc822)
@@ -1,3 +1,3 @@
1
1
  class OpeningHours
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -228,6 +228,8 @@ describe OpeningHours do
228
228
  before do
229
229
  @hours = OpeningHours.new("9:00 AM", "4:00 PM", "Europe/Moscow")
230
230
  @hours.break :fri, "01:00 PM", "01:30 PM"
231
+ @hours.break :sat, "01:00 PM", "01:30 PM"
232
+ @hours.break :sun, "01:25 PM", "01:55 PM"
231
233
  end
232
234
 
233
235
  it "should open at 1:30 pm after the break" do
@@ -241,6 +243,10 @@ describe OpeningHours do
241
243
  it "should open at 2:00 pm next day" do
242
244
  @hours.calculate_deadline(8*60*60, "Mar 22, 2013 01:00 PM +0400").should == Time.zone.parse("Mar 23, 2013 2:00 PM").to_formatted_s(:rfc822)
243
245
  end
246
+
247
+ it "should open at 1:30 pm next day" do
248
+ @hours.calculate_deadline(7*60*60, "Mar 22, 2013 01:00 PM +0400").should == Time.zone.parse("Mar 23, 2013 1:30 PM").to_formatted_s(:rfc822)
249
+ end
244
250
  end
245
251
 
246
252
  context "with breaks and now open" do
@@ -260,6 +266,21 @@ describe OpeningHours do
260
266
  end
261
267
  end
262
268
 
269
+ context "with currently not in break" do
270
+ before do
271
+ open_time = Time.local(Date.today.year, Date.today.month, Date.today.day, Time.now.hour-2).strftime("%I:%M %p")
272
+ close_time = Time.local(Date.today.year, Date.today.month, Date.today.day, Time.now.hour+5).strftime("%I:%M %p")
273
+ break_start_time = Time.local(Date.today.year, Date.today.month, Date.today.day, Time.now.hour-1).strftime("%I:%M %p")
274
+ break_end_time = Time.local(Date.today.year, Date.today.month, Date.today.day, Time.now.hour-1, 30).strftime("%I:%M %p")
275
+ @hours = OpeningHours.new(open_time, close_time, "Europe/Berlin")
276
+ @hours.break OpeningHours::WEEK_DAYS[Date.today.wday], break_start_time, break_end_time
277
+ end
278
+
279
+ it "should should be open" do
280
+ @hours.now_open?.should == true
281
+ end
282
+ end
283
+
263
284
  context "with currently in break" do
264
285
  before do
265
286
  open_time = Time.local(Date.today.year, Date.today.month, Date.today.day, Time.now.hour-2).strftime("%I:%M %p")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opening_hours
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-26 00:00:00.000000000 Z
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec