bokmann / business_time

Support for doing time math in business hours and days
MIT License
1.27k stars 211 forks source link

Allow business hours that cross midnight #227

Open jmanian opened 6 months ago

jmanian commented 6 months ago

It's theoretically possible to have working hours that cross midnight, like for example 11 pm to 7 am. Right now this doesn't seem to be supported.

For example:

time = ActiveSupport::TimeZone.new("America/New_York").now
# Thu, 07 Mar 2024 14:56:02.154340000 EST -05:00

BusinessTime::Config.with(beginning_of_workday: "2:00 pm", end_of_workday: "3:00 pm") { time.during_business_hours? }
# true

BusinessTime::Config.with(beginning_of_workday: "2:00 pm", end_of_workday: "12:01 am") { time.during_business_hours? }
# false

BusinessTime::Config.with(beginning_of_workday: "11:50 pm", end_of_workday: "3:00 pm") { time.during_business_hours? }
# false

It would be nice to support this.

jmanian commented 6 months ago

Looking at the definition of during_business_hours? I see how it could be altered to support this, but I'm not sure whether it should be handled in a more central way or whether there are other methods that need to handle this scenario differently as well, to be consistent.