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

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

Open
jgmontoya opened this issue Jun 1, 2020 · 2 comments

Comments

@jgmontoya
Copy link

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?

@jinfiesto
Copy link

jinfiesto commented Sep 28, 2020

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.

@rmm5t
Copy link
Collaborator

rmm5t commented Jun 26, 2022

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

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

No branches or pull requests

3 participants