working_hours icon indicating copy to clipboard operation
working_hours copied to clipboard

How to do that specific day to change working hours when I calculate time ?

Open FabioNascimento opened this issue 7 years ago • 2 comments

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 ?

FabioNascimento avatar Apr 29 '17 17:04 FabioNascimento

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 ?

jarthod avatar May 01 '17 12:05 jarthod

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

Intrepidd avatar May 02 '17 08:05 Intrepidd

Similar to #11 , closing as stale

Intrepidd avatar Jan 24 '24 12:01 Intrepidd