Question

How to find the first and last working day of the month

Hello,

I have a small requirement to find the first and last working/business day of the month. Is there any pega OOTB function exists for this scenario. if not, please help with any other idea(java code) to achieve the same.

Sample Input : Year & Month ( 2019 & Nov )

Expected first and last business day of Nov 2019: 01-Nov(friday) & 29-Nov(friday).

Comments

Keep up to date on this post and subscribe to comments

November 19, 2019 - 2:55am

Hello, 

Can you use any of those existing functions. Or copy it to create your own one maybe:

November 20, 2019 - 3:33am

Hi @MarcLasserre_GCS,

Thanks for your input.

Confirmed that there is no OOTB function to find the first and last business date of the month. 

Done this scenario with own java code. updating the same here for others reference. Thanks. 

-----

PublicAPI tools = ThreadContainer.get().getPublicAPI();

String toAddDate = "0";
String inputDate = year.concat(month);
String specificDateFormat = toAddDate.concat(specificDate);
String firstInputDay = inputDate.concat(specificDateFormat);

if ((year == null || year.isEmpty()) && (month == null || month.isEmpty()) && (specificDate == null || specificDate.isEmpty())){
  return null;
}

if (calendarName.equals("") || (calendarName == null)){
  calendarName="JPDefaultTest";
}

if ((calendarName != "JPDefaultTest") || (calendarName != null)){
   return null;
}

if (specificDate == "1"){
    String strFirstBusinessDay =  pega_rules_businesscalendar.addDays(firstInputDay, 0, true, calendarName);
    return strFirstBusinessDay; 
} else if (specificDate == "2"){
    int intYear = Integer.parseInt(year);
    int intMonth = Integer.parseInt(month);
    Calendar cal = Calendar.getInstance();;
    cal.clear();
    cal.set(intYear, intMonth, 1);
    cal.add(Calendar.DATE, -1);
    int day = cal.get(Calendar.DATE);
    String strDay = String.valueOf(day);
    String lastDay = inputDate.concat(strDay);
    if (pega_rules_businesscalendar.isBusinessDay(lastDay,"JPDefaultTest")){
       return lastDay;
    } else {
        do{
           cal.add(Calendar.DATE, -1);
          } while (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
           || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY );
        int Bussinessday = cal.get(Calendar.DATE);
        String strBussDay = String.valueOf(Bussinessday);
        String lastBussDay = inputDate.concat(strBussDay);
        return lastBussDay;
      } 
  }
return null;

----