Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix end of workday critical bug #84

Merged
merged 3 commits into from
Jun 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.16)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
atomic (1.1.14)
activesupport (4.1.0)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
i18n (0.6.9)
json (1.8.1)
minitest (5.2.2)
minitest-rg (5.0.0)
minitest (~> 5.0)
multi_json (1.8.4)
rake (10.1.1)
rdoc (4.1.1)
json (~> 1.4)
thread_safe (0.1.3)
atomic
thread_safe (0.3.3)
tzinfo (1.1.0)
thread_safe (~> 0.1)

Expand Down
1 change: 1 addition & 0 deletions lib/business_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'active_support'
require 'active_support/time'
require 'time'
require 'yaml'

require 'business_time/config'
require 'business_time/business_hours'
Expand Down
2 changes: 1 addition & 1 deletion lib/business_time/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class << self
def end_of_workday(day=nil)
if day
wday = work_hours[int_to_wday(day.wday)]
wday ? (wday.last =~ /0{1,2}\:0{1,2}/ ? "23:59:59" : wday.last) : config[:end_of_workday]
wday ? (wday.last =~ /^0{1,2}\:0{1,2}$/ ? "23:59:59" : wday.last) : config[:end_of_workday]
else
config[:end_of_workday]
end
Expand Down
16 changes: 16 additions & 0 deletions test/test_calculating_business_duration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,20 @@
}
assert_equal 68.hours, friday.business_time_until(monday)
end

it 'properly calculate overnight business time' do
BusinessTime::Config.work_hours = {
mon: ["08:00","20:00"],
tue: ["08:00","20:00"],
}
BusinessTime::Config.holidays = []

created_at = Time.local(2014, 05, 12, 20, 50) #yesterday night 20:50
published_at = Time.local(2014, 05, 13, 8, 10) #today morning 08:10
assert created_at.monday?
assert published_at.tuesday?

assert_equal 10.minutes, created_at.business_time_until(published_at)
end

end
12 changes: 12 additions & 0 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
assert_equal([1,2,4,5], BusinessTime::Config.weekdays.sort)
end

it 'end of workday not freakout' do
BusinessTime::Config.work_hours = {
:mon=>["9:00","20:00"],
:tue=>["9:00","17:00"],
:thu=>["9:00","17:00"],
:fri=>["9:00","17:00"]
}

monday = Time.local(2014, 05, 12, 20, 50)
assert_equal "20:00", BusinessTime::Config.end_of_workday(monday)
end

it "load config from YAML files" do
yaml = <<-YAML
business_time:
Expand Down