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