MySQL Function to calculate closing WorkDay date given elapsed working time
On my post MySQL function to calculate elapsed working time I was asked in comments if the assumptions can be reversed such that given start date, starting time and closing time of site and the elapsed working hours, function should return the closed date. I was convinced that it will be possible to achieve this with minor tweaks to original logic and so I only concentrated on original code and how to tweak it to achieve the result. It is very likely that there might exist a more elegant solution but frankly I did not have a usecase I did find a usecase afterall - Clue was in redefining the problem description for this. Presented below is the function that with my minimal testing seems to give correct results. Feel free to try it and as always any feedback is welcome.
Problem Description:
Find out the WorkDay date by when a ticket must be closed given:
- Country of site for which incident was logged.
- Time and Date when Incident was logged.
- Elapsed working hours in decimal. (Ten and a half hours as 10.5 and so on)
- Opening time of the site for which the incident was logged.
- Closing Time of the site for which incident was logged.
- SLA Type - Is the output date to be based purely on number of hours or based on SLA in days (eg: Next Business Day).
Assumption
It is assumed that opening and closing times are same on all working days and that all the sites are closed on holidays and weekends.