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

Support 11pm close times #230

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sotm-ross
Copy link

Why?

While working on a project where I needed to provide our hours in UTC times, I noticed a bug with 11pm closing times where an hour would be "eaten" by business_hours.after(time) if time was right up against the end of the work day/11pm:

BusinessTime::Config.beginning_of_workday = "2pm"
BusinessTime::Config.end_of_workday = "11pm"
# standard Mon-Friday work week

monday = Time.parse("2024/09/30 9:00pm")
tuesday = Time.parse("2024/10/01 4:00pm")
4.business_hours.before(tuesday) == monday # true
4.business_hours.after(monday) == tuesday # false

Strangely, the reverse problem didn't exist. 4.business_hours.before(<Tues@4pm>) accurately returned Mon@9pm.

What?

  • Refactor calculate_after:
    • Instead of defaulting to Time.roll_forward(after_time) when after_time is 00:00:00, use the logic for checking if
      after_time is outside of work hours instead so that the delta isn't lost.
    • That introduced a bug with the exceptions in place for closing times of 00:00:00, so I also added a check to ignore the delta if it was only 1 second.'
  • match the pattern in calculate_before for simplicity.

Before, the if(after_time == midnight) branch "swallowed" an hour
if after_time was midnight but the closing time was 11pm since
there was no delta computation in that branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant