We have a PHP-based scheduling system that was developed in the house and developed over the years, however, one part of the information presented to users is the number of working days left in each project.
Currently, I just take the difference between the current date and the end date of the project and dividing by 7 and multiplying by 5. This was enough for a long time and mostly accurate enough for employees who work full time from Monday to Friday. However, now we have several employees who work only with an odd day a week.
The scheduling system knows what days the staff work, this information is stored in a line in the user class, for working time it is a full day, the value will be NNYYYYY(which means ssMTWTF).
I could very easily make the result more accurate by dividing the difference between the two dates by seven, and then multiplying by the number of days during which they work, but by making this change, I am considering creating a much more accurate means of calculating the real value.
The easiest way that comes to mind is simply to use a cycle between two dates, comparing the day of the week with the user's work template, adding it to the counter on the days when the user is working on that day.
Given that this calculation should be performed on average about 30 times on the watch page due to the number of projects on the schedule, and projects can span 12 or 18 months at a time (which is a lot of cycles for each page load), I wonder if there is a more efficient way to do it in php?
Bryan source
share