BusinessHours Class
Namespace
BusinessHours Methods
The following are methods for BusinessHours. All methods are static.
add(businessHoursId, startDate, intervalMilliseconds)
Signature
public static Datetime add(String businessHoursId, Datetime startDate, Long intervalMilliseconds)
Parameters
Return Value
Type: Datetime
addGmt(businessHoursId, startDate, intervalMilliseconds)
Signature
public static Datetime addGmt(String businessHoursId, Datetime startDate, Long intervalMilliseconds)
Return Value
Type: Datetime
diff(businessHoursId, startDate, endDate)
Signature
public static Long diff(String businessHoursId, Datetime startDate, Datetime endDate)
Return Value
Type: Long
isWithin(businessHoursId, targetDate)
Signature
public static Boolean isWithin(String businessHoursId, Datetime targetDate)
Parameters
Return Value
Type: Boolean
Example
The following example finds whether a given time is within the default business hours.
1// Get the default business hours
2BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
3
4// Create Datetime on May 28, 2013 at 1:06:08 AM in the local timezone.
5Datetime targetTime = Datetime.newInstance(2013, 5, 28, 1, 6, 8);
6
7// Find whether the time is within the default business hours
8Boolean isWithin= BusinessHours.isWithin(bh.id, targetTime);nextStartDate(businessHoursId, targetDate)
Signature
public static Datetime nextStartDate(String businessHoursId, Datetime targetDate)
Parameters
Return Value
Type: Datetime
Example
The following example finds the next date starting from the target date when business hours reopens. If the target date is within the given business hours, the target date is returned. The returned time is in the local time zone.
1// Get the default business hours
2BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
3
4// Create Datetime on May 28, 2013 at 1:06:08 AM in the local timezone.
5Datetime targetTime = Datetime.newInstance(2013, 5, 28, 1, 6, 8);
6// Starting from the targetTime, find the next date when business hours reopens. Return the target time.
7
8// if it is within the business hours. The returned time will be in the local time zone
9Datetime nextStart = BusinessHours.nextStartDate(bh.id, targetTime);