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

Account for config.end_of_workday=00:00:00 #231

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions lib/business_time/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ class << self
# BusinessTime::Config.end_of_workday = "5:30 pm"
# someplace in the initializers of your application.
def end_of_workday(day=nil)
eod = config[:end_of_workday]
if day
wday = work_hours[int_to_wday(day.wday)]
wday ? (wday.last == ParsedTime.new(0, 0) ? ParsedTime.new(23, 59, 59) : wday.last) : config[:end_of_workday]
else
config[:end_of_workday]
eod = wday.last if wday
end

eod == ParsedTime.new(0, 0) ? ParsedTime.new(23, 59, 59) : eod
end

# You can set this yourself, either by the load method below, or
Expand Down
11 changes: 11 additions & 0 deletions test/test_business_hours.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@
expected = Time.parse("July 6th 2010, 9:50 am")
assert_equal expected, tuesday_morning
end

it "respect end_of_workday with 12am closing time" do
two_before_close = Time.parse("2024-11-04 22:00")
two_after_open = Time.parse("2024-11-05 17:00")

BusinessTime::Config.beginning_of_workday = "3pm"
BusinessTime::Config.end_of_workday = "12am"

assert_equal two_after_open, 4.business_hours.after(two_before_close)
assert_equal two_before_close, 4.business_hours.before(two_after_open)
end
end

describe "when adding/subtracting negative number of business hours" do
Expand Down
Loading