top of page

Counting Saturday and Sunday while calculating Absence Duration

Organizations often works on their specific Work Schedule, general work schedule is 5 days a week. Due to this work schedule defined into the system and mapped to the assignments weekends and public holidays never gets counted while calculating absence duration for the period of applied leave.


There could be scenarios where we need to count weekends as well (for certain countries it is Saturday, Sunday and for certain it is Friday, Saturday), we can do this utilizing Global Absence Type Duration Fast Formula.


Fast Formula once created needs to get mapped at Absence Type level, Conversion formula section -


Below sample code to count Saturday, and Sunday, and exclude them if it is Public Holiday.

/*********************************************************************
FORMULA NAME: Sick_Leave_Duration
FORMULA TYPE: Global Absence Type Duration Formula
DESCRIPTION: This formula returns the duration inclusive of Friday, Saturday
Change History:
Name	         Date		Version  	Comments
-------------------------------------------------------------------------------
Fusion Forest	19-JUL-2020	v1.0	Initial Version
**********************************************************************/

DEFAULT FOR IV_START_DATE IS '4712/12/31 00:00:00' (date)
DEFAULT FOR IV_END_DATE IS '4712/12/31 00:00:00' (date)

DEFAULT_DATA_VALUE FOR PER_EXT_CAL_COVERAGE_START_DATE_TIME IS '4712/12/31 00:00:00' (date)

INPUTS ARE IV_START_DATE (date), IV_END_DATE (date)

	L_EFFECTIVE_DATE = GET_CONTEXT(EFFECTIVE_DATE, '1951/01/01 00:00:00' (DATE))

	l_start_time = '00:00'
	l_end_time = '23:59'
	l_start_date = to_date(to_char(IV_START_DATE,'DD/MM/RRRR')||' '||l_start_time,'DD/MM/RRRR HH24:MI:SS')
	l_end_date = to_date(to_char(IV_END_DATE,'DD/MM/RRRR')||' '||l_end_time,'DD/MM/RRRR HH24:MI:SS') 

	/*l_start_date = IV_START_DATE */
	/*l_end_date = IV_END_DATE*/

	l_entry_duration_d = 0
	l_total_duration_d = 0
	l_saturdays = 0
	l_PH_onSat = 0

	l_entry_duration_d = GET_PAY_AVAILABILITY ('ASSIGN',
		l_start_date,
		l_end_date,
		'Y',
		'Y',
		'Y',
		'Y',
		'D')

		l_saturdays = FLOOR((DAYS_BETWEEN(ADD_DAYS(NEXT_DAY(l_end_date,'SATURDAY'),-7),NEXT_DAY(ADD_DAYS(l_start_date,-1),'SATURDAY')) / 7) + 1)
		l_sundays = FLOOR((DAYS_BETWEEN(ADD_DAYS(NEXT_DAY(l_end_date,'SUNDAY'),-7),NEXT_DAY(ADD_DAYS(l_start_date,-1),'SUNDAY')) / 7) + 1)
		
		l_total_duration_d = l_entry_duration_d + l_sundays + l_saturdays

		i=1
		
		CHANGE_CONTEXTS(EFFECTIVE_DATE = l_end_date)
		(
			WHILE PER_EXT_CAL_COVERAGE_START_DATE_TIME.EXISTS(i)
			LOOP
			(
				IF (PER_EXT_CAL_COVERAGE_START_DATE_TIME[i] > l_start_date AND PER_EXT_CAL_COVERAGE_START_DATE_TIME[i] < l_end_date)
				THEN 
			(
				IF NEXT_DAY(ADD_DAYS(PER_EXT_CAL_COVERAGE_START_DATE_TIME[i],-1),'SATURDAY') = PER_EXT_CAL_COVERAGE_START_DATE_TIME[i]
				THEN
				(
				 l_PH_onSat = l_PH_onSat + 1
				)
				
				IF NEXT_DAY(ADD_DAYS(PER_EXT_CAL_COVERAGE_START_DATE_TIME[i],-1),'SUNDAY') = PER_EXT_CAL_COVERAGE_START_DATE_TIME[i]
				THEN
				(
				 l_PH_onSun = l_PH_onSun + 1
				)
			)
		i=i+1
		
			)
		)

	l_total_duration_d = l_total_duration_d - l_PH_onSat - l_PH_onSun

DURATION = l_total_duration_d

RETURN DURATION

Comments


bottom of page