Skip to main content
fix MondayStartDate into MondayStartTime , fix bt.MondayStartTime.seconds into bt.MondayStartTime.second
Source Link
Public static boolean isHoliday(Date checkDate) {
    BusinessHours bt = [SELECT Id,MondayStartDateMondayStartTime FROM BusinessHours 
        WHERE isDefault = true];
    Datetime checkDatetime = Datetime.newInstance(checkDate.year(), checkDate.month(), checkDate.day(), 
        bt.MondayStartDateMondayStartTime.hour(), bt.MondayStartDateMondayStartTime.minute(), bt.MondayStartDateMondayStartTime.secondssecond());
    return !BusinessHours.isWithin(bt.Id,checkDateTime);
}

the method isWithin(businessHoursId, targetDate) return true if the inserted datetime is a working day, based on the BusinessHours passed (Apex Developer Guide)

In this case, I'm assuming that the work starts at the same hour for each working day of the week.

Public static boolean isHoliday(Date checkDate) {
    BusinessHours bt = [SELECT Id,MondayStartDate FROM BusinessHours 
        WHERE isDefault = true];
    Datetime checkDatetime = Datetime.newInstance(checkDate.year(), checkDate.month(), checkDate.day(), 
        bt.MondayStartDate.hour(), bt.MondayStartDate.minute(), bt.MondayStartDate.seconds());
    return !BusinessHours.isWithin(bt.Id,checkDateTime);
}

the method isWithin(businessHoursId, targetDate) return true if the inserted datetime is a working day, based on the BusinessHours passed (Apex Developer Guide)

In this case, I'm assuming that the work starts at the same hour for each working day of the week.

Public static boolean isHoliday(Date checkDate) {
    BusinessHours bt = [SELECT Id,MondayStartTime FROM BusinessHours 
        WHERE isDefault = true];
    Datetime checkDatetime = Datetime.newInstance(checkDate.year(), checkDate.month(), checkDate.day(), 
        bt.MondayStartTime.hour(), bt.MondayStartTime.minute(), bt.MondayStartTime.second());
    return !BusinessHours.isWithin(bt.Id,checkDateTime);
}

the method isWithin(businessHoursId, targetDate) return true if the inserted datetime is a working day, based on the BusinessHours passed (Apex Developer Guide)

In this case, I'm assuming that the work starts at the same hour for each working day of the week.

grammartical fix
Source Link
Jackson Chen
  • 4.8k
  • 2
  • 17
  • 52
Public static boolean isHoliday(Date checkDate) {
    BusinessHours bt = [SELECT Id,MondayStartDate FROM BusinessHours 
        WHERE isDefault = true];
    Datetime checkDatetime = Datetime.newInstance(checkDate.year(), checkDate.month(), checkDate.day(), 
        bt.MondayStartDate.hour(), bt.MondayStartDate.minute(), bt.MondayStartDate.seconds());
    return !BusinessHours.isWithin(bt.Id,checkDateTime);
}

the method isWithin(businessHoursId, targetDate) return true if the inserted datetime is a working day, based on the BusinessHours passed (Apex Developer Guide)

inIn this case i'm supposing, I'm assuming that the work starts at the same hour for each working day of the week.

Public static boolean isHoliday(Date checkDate) {
    BusinessHours bt = [SELECT Id,MondayStartDate FROM BusinessHours 
        WHERE isDefault = true];
    Datetime checkDatetime = Datetime.newInstance(checkDate.year(), checkDate.month(), checkDate.day(), 
        bt.MondayStartDate.hour(), bt.MondayStartDate.minute(), bt.MondayStartDate.seconds());
    return !BusinessHours.isWithin(bt.Id,checkDateTime);
}

the method isWithin(businessHoursId, targetDate) return true if the inserted datetime is a working day, based on the BusinessHours passed (Apex Developer Guide)

in this case i'm supposing that the work starts at the same hour for each working day of the week.

Public static boolean isHoliday(Date checkDate) {
    BusinessHours bt = [SELECT Id,MondayStartDate FROM BusinessHours 
        WHERE isDefault = true];
    Datetime checkDatetime = Datetime.newInstance(checkDate.year(), checkDate.month(), checkDate.day(), 
        bt.MondayStartDate.hour(), bt.MondayStartDate.minute(), bt.MondayStartDate.seconds());
    return !BusinessHours.isWithin(bt.Id,checkDateTime);
}

the method isWithin(businessHoursId, targetDate) return true if the inserted datetime is a working day, based on the BusinessHours passed (Apex Developer Guide)

In this case, I'm assuming that the work starts at the same hour for each working day of the week.

Source Link

Public static boolean isHoliday(Date checkDate) {
    BusinessHours bt = [SELECT Id,MondayStartDate FROM BusinessHours 
        WHERE isDefault = true];
    Datetime checkDatetime = Datetime.newInstance(checkDate.year(), checkDate.month(), checkDate.day(), 
        bt.MondayStartDate.hour(), bt.MondayStartDate.minute(), bt.MondayStartDate.seconds());
    return !BusinessHours.isWithin(bt.Id,checkDateTime);
}

the method isWithin(businessHoursId, targetDate) return true if the inserted datetime is a working day, based on the BusinessHours passed (Apex Developer Guide)

in this case i'm supposing that the work starts at the same hour for each working day of the week.