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

initiate business_time instead of global definitions #181

Closed
fluxsaas opened this issue Mar 28, 2018 · 3 comments
Closed

initiate business_time instead of global definitions #181

fluxsaas opened this issue Mar 28, 2018 · 3 comments

Comments

@fluxsaas
Copy link

Hey!

would it make sense to allow instantiating a buisness_time with configs e.g.

buisness_time = BusinessTime.new(
  beginning_of_workday: "8:30 am",
  end_of_workday: "5:30 pm",
  holidays: [Date.parse("July 5th, 2010")],
  work_week: [:mon, :tue, :wed, :thu, :fri],
)

this would help me in cases where you have to change the configs for specific use cases. (e.g. a specific user in the the app has specific holidays based on country)

@jmanian
Copy link
Contributor

jmanian commented Sep 13, 2018

I have need for this as well. Or a way to set config parameters per calculation, e.g.

1.business_day.after(time, beginning_of_workday: '9 am', end_of_workday: '5 pm')

I have the same situation as @fluxsaas where in some cases I need to use one set of config values and in another situation I need another. The solution I have at the moment is whenever I need something other than my default config I update beginning_of_workday and end_of_workday, I make the calculation, and then I set them back to the original.

original_beginning = BusinessTime::Config.beginning_of_workday
original_end = BusinessTime::Config.end_of_workday
BusinessTime::Config.beginning_of_workday = '9 am'
BusinessTime::Config.end_of_workday = '5 pm'
1.business_day.after(time)
BusinessTime::Config.beginning_of_workday = original_beginning
BusinessTime::Config.end_of_workday = original_end

However I'm running this in a multi-threaded environment (sidekiq), and this approach is not thread safe. I just tracked down an issue where the setting in one thread was inadvertently used for the calculation in another thread.

@jmanian
Copy link
Contributor

jmanian commented Sep 13, 2018

It looks like the undocumented method shown in #168 would solve my problem. Maybe it works for you too @fluxsaas?

@bokmann
Copy link
Owner

bokmann commented Mar 4, 2019

I agree this is an interesting use case, but its not at all what this gem was meant to solve. As the docs say, this was meant to solve a particular business problem, does that well, and is pretty feature complete. There are other date time libraries that may suit you, or you're free to take this code as an 80% solution and work up your own.

@bokmann bokmann closed this as completed Mar 4, 2019
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