business_time icon indicating copy to clipboard operation
business_time copied to clipboard

business_days.after weird behaviour when not in workday and out of business hours.

Open jgmontoya opened this issue 5 years ago • 2 comments

I have the following business logic:

eta(x) = x if x is during business hours eta(x) = next business day otherwise

Let's say my business hours go from monday to friday until 18:00

So to implement it, I was doing this: 0.business_days.after(now) which works correctly in almost every case.

However when on a weekend (either saturday or sunday) after 18, (say for example Sun, 31 May 2020 at 18:29) the expected result is to return the next day (Mon, 01 Jun 2020) but the actual output is a day off (Tue, 02 Jun 2020).

Am I missing something?

jgmontoya avatar Jun 01 '20 22:06 jgmontoya

The issue is this method. Basically, the roll forward logic is buggy and it fast forwards to Monday after business, in your case, and then applies another roll-forward which pushes the day to Tuesday. I don't see much activity here, so you'll probably have to fork and patch, or deal with it in your client code.

To fix it in your client code, you can use Time.first_business_day(day), on weekends, which appears to give the correct result, except if the start is Friday after business, in which case you'll want to push the day forward by one before calling the above.

Alternatively, depending on your use case, you may be able to push the time into the business hours window and that may also fix the issue.

jinfiesto avatar Sep 28 '20 05:09 jinfiesto

This sounds more like you might be running into a time zone issue -- i.e. when the the time in UTC has actually rolled over to the next day but you might be expecting the date math to run under your local time zone.

Possibly, it sounds like you're using busines_days instead of business_hours to calculate your business logic:

>> Date.current
=> Sun, 26 Jun 2022
>> 1.business_day.from_now
=> 2022-06-28 09:00:00 -0600
>> 3.business_hours.from_now
=> 2022-06-27 12:00:00 -0600

rmm5t avatar Jun 26 '22 18:06 rmm5t