Salesforce Winter ’14 offers a couple new methods for BusinessHours. One is for checking to see if a datetime is within your companies business hours (currently set) and the other is for checking with the next available open datetime is. Here is a quick example in Apex.
1.) Navigate out to your Organization Busienss Hours, for this example I am working with the Default entry.
2.) I’ve set my business hours (currently its a Wednesday 8/28/2013 about 1pm EST) as the following. I set Thursday as being closed so we can test the nextstartdate method to see if we get Friday.
3.) In the developer console I’ve written the following code. The first test is to see if we are in an open date and time. The second test is to take the current date and time, add 6 hours to make it Wednesday evening and then check if we are within hours and if not when is the next open date and time.
4.) After running the code, you’ll see my results below in the result log. My first test was true, which is what we expected (Wednesday at 1pm is within the business hours for Wednesday 8am to 5pm). The second test was false, which is always what we expected (Wednesday at 7pm is not within the business hours of 8m to 5pm) and also it shows the next open day as Friday 8/30. Note the time given is due to system time being returned in the developer console. Very powerful methods you can take advantage of!