working_hours
working_hours copied to clipboard
How to do that specific day to change working hours when I calculate time ?
Hello,
First of all, thanks for this gem !! 👍
Here I created a plugin of redmine ( that I coding now ) where I need to calculate SLA of time response and I found this gem useful for me, but I have a situation here that I would like that a day working hour will be different Like a holiday I need to calculate spend time using diferente working hour. Let me show the code to clarify my need :
# Configure working hours for all normaly days
WorkingHours::Config.working_hours = {
:mon => {'09:00' => '12:00', '13:00' => '18:00'},
:tue => {'09:00' => '12:00', '13:00' => '17:00'},
:wed => {'09:00' => '12:00', '13:00' => '17:00'},
:thu => {'09:00' => '12:00', '13:00' => '17:00'},
:fri => {'09:00' => '12:00', '13:00' => '17:05:30'},
:sat => {'19:00' => '24:00'},
#Here my suggest to I need - this data is monday but I would like to change working hours
'2017-05-01' => {'10:00' => '12:00', '14:00' => '16:00'}
}
# Configure timezone (uses activesupport, defaults to UTC)
WorkingHours::Config.time_zone = 'Paris'
# Configure holidays
WorkingHours::Config.holidays = [Date.new(2014, 12, 31)]
# here I can get hours of work considering a Day diferente of others days..
Is there a form to get this behavior with this gem ?
Hello @FabioNascimento,
This is an interesting use-case but it's unfortunately not supported by this gem. Feel free to write a PR if you want though, I like the idea I just would prefer another config variable to make it clear and avoid mixing days with days of week, something like:
WorkingHours::Config.exceptions = {
'2017-05-01' => {'10:00' => '12:00', '14:00' => '16:00'}
}
What do you think @Intrepidd ?
Hey @FabioNascimento indeed it's an interesting use case.
Having the exceptions in a config var like @jarthod suggested would work but I'm afraid it's limited as people will most likely want to store there exceptions in the database and therefore we'd have to call a lambda or something each time we compute working hours, but it's going to be a real pain for performance then :(
I don't think there's a silver bullet to beat that problem
Similar to #11 , closing as stale