Determine Earliest Business Date
Suppose a customer may sends his/her request at any day, any time. The request can only be processed during business hours (weekdays, 9am to 5pm). Given a time at which the customer makes his/her request, I wish to determine the day that the request can be processed.
Examples:
- If request is received at 2010-03-01 13:00:00 (Monday), the request can be processed on the same day.
- If request is received at 2010-03-01 17:00:00 (Monday), the request will be processed on the following day (2010-03-02), because the cut-off time is 5pm.
- If request is received at 2010-03-05 17:00:00 (Fri), the request will be processed on the following Monday (2010-03-08). It has past the cut-off time, and the request will not be processed during weekends.
- If request is received at 2010-03-07 00:00:00 (Sunday), the request will be processed on the following Monday (2010-03-08). The request will not be processed during weekends.
I have written a function that determine the earliest business date in PHP. It returns an integer result (Unix timestamp).
Enchancements:
- Allow user to specify cut-off time
- Check for public holidays