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

[Bug] business_days.after inconsistencies #206

Closed
pmcnano opened this issue Mar 18, 2021 · 3 comments
Closed

[Bug] business_days.after inconsistencies #206

pmcnano opened this issue Mar 18, 2021 · 3 comments

Comments

@pmcnano
Copy link

pmcnano commented Mar 18, 2021

I wasn't sure to post this issue or not because I have no clue what is happening and I don't have much data, or at least I think.

I noticed some day calculations were not working properly in our app so I began troubleshooting it.
This date is returned through an API call. So my app receives some params and returns data, which includes this date.

If I run the request through my production web server, my date is off. However, every 10-15 requests, it would return the correct date.
If I run the same code through production console it is okay.

my config:

business_time:
  beginning_of_workday: 12:00:00 am
  end_of_workday: 11:59:59.999999 pm
  work_week:
    - mon
    - tue
    - wed
    - thu
    - fri

This is basically what's running:

days = 2
now = 'Wed, 17 Mar 2021 20:15:16 EDT -04:00'.to_time
date = days.business_days.after(now).to_date

And it's returning Monday 22 2021 instead of Friday 18 2021.

I decided to add some debugging in production and also trying to fetch the date in a different way:

days = 2
now = 'Wed, 17 Mar 2021 20:15:16 EDT -04:00'.to_time
date = days.business_days.after(now).to_date
date2 = days.business_days.after(now.to_date)
if warehouse.code == 'MA' && days == 2 && date != '19 March 2021'.to_date
  message = {
    time_now: Time.now,
    time_zone_now: Time.zone.now,
    warehouse_local: now,
    date: date,
    date2: date2
  }
  Rails.logger.info(message)
end
date

The results were the following:

2021-03-18T00:15:16.468557+00:00 app[web.1]: I, [2021-03-18T00:15:16.468381 #210]  INFO -- : {:time_now=>2021-03-18 00:15:16.468218979 +0000, :time_zone_now=>Thu, 18 Mar 2021 00:15:16 UTC +00:00, :warehouse_local=>Wed, 17 Mar 2021 20:15:16 EDT -04:00, :date=>Mon, 22 Mar 2021, :date2=>Fri, 19 Mar 2021}
2021-03-18T00:15:57.273594+00:00 app[web.1]: I, [2021-03-18T00:15:57.273391 #100]  INFO -- : {:time_now=>2021-03-18 00:15:57.273113129 +0000, :time_zone_now=>Thu, 18 Mar 2021 00:15:57 UTC +00:00, :warehouse_local=>Wed, 17 Mar 2021 20:15:57 EDT -04:00, :date=>Mon, 22 Mar 2021, :date2=>Fri, 19 Mar 2021}

As you can see, date2 was calculated correct. I am fixing my issue this way, but there's definitely something off as running the same thing in console, same environment returns the correct date too.

@rmm5t
Copy link
Collaborator

rmm5t commented Mar 18, 2021

March 18, 2021 is a Thursday. 2 business days after that would be the Monday, March 22, 2021.

What am I misunderstanding about your report here?

@pmcnano
Copy link
Author

pmcnano commented Mar 18, 2021

Jeez. I apologize, the now date is not the correct one. I wasn't and probably am still not in a correct state of mind.

The now is in a specific time zone. I have edited and fixed the original comment.

@pmcnano
Copy link
Author

pmcnano commented May 28, 2021

Closing due to finding the real culprit. Since #209 was happening, my config was not present and hence 9pm was after the default 9-5pm work time.

@pmcnano pmcnano closed this as completed May 28, 2021
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

2 participants