+ Start a Discussion
Rajesh ShahRajesh Shah 

Logic to find if given date falls on an Holiday or not

Based on the holidays mentioned in the Company Profile, I need to find out if a given date falls on an Holiday or not? Currently I am doing this using a complex logic where based on all the permutations and combinations like Yearly, Monthly, Daily, etc I try to see if it is a holiday or not. I just wanted to know if there is a simpler way to do this that I don't know about.


Are you already querying the "Holiday" object for this information?
Rajesh ShahRajesh Shah
Yes. But there are so many possible combinations possible like Last Tuesday of every month, saturday of every week, 1st Friday of every 3 months, etc which is making the whole logic really complex.

I think the idea with Holidays is that, although there are rules like Third Monday, etc., Holidays relies on someone already having computed the holidays.  Once those computed dates are entered into Holidays, you then simply query against those to validate a date, right? 


Just my $0.02.  If someone has a better idea I would love to hear it.  Cheers

Message Edited by ReidC on 03-03-2010 12:23 PM
Rajesh ShahRajesh Shah

Static holidays defined in the system are really easy to handle. The problem arises for recurring holidays especially when the condition is complex like Every 2nd Sunday in every 2 months.

Also, what does the field RecurrenceDayOfWeekMask signifies? I tried with few examples but could not understand the value.


what about this, making use of the standard Holiday and WorkingDays specified in Salesforce.com:


    global static Boolean isHoliday(Date checkDate){
        BusinessHours stdBusinessHours = [select id from Businesshours where isDefault = true];
        Date outDate = (BusinessHours.add(stdBusinessHours.id, checkDate, 1)).date();
        if(checkDate == outDate){
            return false;
        } else {
            return true;