You are on page 1of 1

/**

* BusinessDays Class
* esta clase solo opera sobre el horario laboral configurado en SFDC para ARGOS
* @author - Nicolás Montejo
* */

public class BusinessDays


{
public BusinessHours bHours;
/**
* Constructor to set business hours name
* */

public BusinessDays(String businessHoursName)


{
//get business hours

bHours = [SELECT Id FROM BusinessHours WHERE Name =: businessHoursName];


}

public BusinessDays()
{
//Get the default business hours
Id bHours = [SELECT Id FROM BusinessHours WHERE IsDefault = true].Id;

//Get the next date when business hours are open. If the specified target
date falls within business hours, this target date is returned.

Datetime targetDate = system.today();


Datetime nextDate = BusinessHours.nextStartDate(bHours, targetDate);

//Check target date occurs within business hours. Holidays are included in
the calculation.

Datetime targetDate1 = system.today();


Boolean isWithinBusinessHour = BusinessHours.isWithin(bHours, targetDate);

//Get the difference between a start and end Datetime based on a specific
set of business hours in milliseconds.

Datetime startDT = system.today();


Datetime endDT = DateTime.Now().AddDays(2);
Long difference = BusinessHours.diff(bHours, startDT, endDT);
Double hours = difference/3600000;

//Adds an interval of time from a start Datetime traversing business hours


only. Returns the result Datetime in the local time zone.

Datetime startDT1 = system.today();


Long intervalMilliseconds = 50000;
Datetime targetDT1 = BusinessHours.add(bHours, startDT,
intervalMilliseconds);}
}
}

You might also like