# computing whether service level times are met

For a ticket reporting tool, I want to compute whether certain service level times (slt) are met. That is (a bit simplified): Was the timespan between opening and closing of the ticket within a certain slt. Now there is also something called a service window (SW), like mo-fr,9:00-17:00. Now to compute whether a slt was met, times not within the SW have to be excluded. Even though not forseen, tickets can be opened or closed outside the SW, since there are other sla wich allow for 24x7 service. An engineer could work on a ticket outside the SW, since it might be easier for him to close a ticket while he is at it. Maybe he was doing work on a related ticket.

In order to determine the time a ticket took between opening and closing time, I though of two algorithms:

1) Distinguish all possible combinations of start_date and end_date beeing within or outside the SW, on different days and so on (I see 8 combinations). Then for each combination, set up a seperate formula to compute the time the ticket took.

Plus: little computational overhead

Minus: Rather complex, lots of code

2) Decide for a smallest possible unit (minutes seem to be apropriate), then for each unit between start_date and end_date, decide whether this unit is inside or outside the SW. If inside, add to the time the ticket took.

Plus: very simple

Minus: big computational overhead.

I am leaning towards 2) since compuation is cheap, simple code is to be preferred, and the rest of the programm contains lots of time consuming db queries, so a little computation will not be noticable.

However, both solutions seem not very elegant to me. Does anyone see a third way?

• Do you actually need to know the time that the ticket took? Or just whether it is greater than a certain service level time? If the latter, could you approach it from the angle of calculating the "deadline time" from the start_date, and then comparing the end_date to that? Nov 18, 2013 at 7:21
• I only need to know if a certain slt is met. So your approach is definatly an improvement over my ideas. But for deadline calculation, I would still resort to Doc Browns method, so I am choosing his algorithm. Nov 18, 2013 at 7:39