Working days to include bank holidays

Discuss your general Proclaim related queries here.
Post Reply
whiteyes
Posts: 19
Joined: Wed Jan 07, 2015 11:37 am

Working days to include bank holidays

Post by whiteyes » Sat Sep 07, 2019 9:24 am

Hi,


I'm having trouble with the following code as it doesnt exclude the bank holiday, any ideas what ive done wrong and how i can correct it? (got this maths from a previous post) using proclaim 3.4


vstart = DAYS-FROM-TODAY( {Date Referral Received.Date} )
vend = DAYS-FROM-TODAY( {Date Expert Instructed.Date} )
#=====
#how many calendar days are between these dates?
vcount = vend - vstart
#=====
#variable to store number of business days in this period:
vbd = 0
#=====
#start on the start date
vday = vstart
#=====
#loop over all days in this period.
WHILE vday <= vend DO
#=====
#convert this to a date
vdate = DATE-FROM-TODAY( vday )
#=====
#Is this date a weekend?
dayofweek = WEEKDAY( vdate )
IF dayofweek = "Saturday" OR dayofweek = "Sunday" THEN
# weekends don't count towards working days - do nothing
ELSE
#it's not a weekend...
#=====

#=====
#what year is this particular date:
vyear = YEAR( vdate )
#=====
#make a comma separated list of bank holiday dates for that year:
vtext = "BANK HOLIDAYS-" + TEXT( vyear )
#=====
#search this list for the particular date
vlist = USER-PROFILE( vtext )
vbh = LISTFIND( vlist , vdate , " , " )
IF vbh <> 0 THEN
#this date IS in the list of bank hol dates - this date is a bank hol - do not add to working days
ELSE
# this particular date is NOT a weekend and NOT a bank hol, so is a working day.
# add 1 to our businessday counter
vbd = vbd + 1
END
END
#advance to next calendar day
vday = vday + 1
#
END
result = vbd

Thanks!

whiteyes
Posts: 19
Joined: Wed Jan 07, 2015 11:37 am

Re: Working days to include bank holidays

Post by whiteyes » Sun Sep 08, 2019 10:07 am

now proclaim freezes when i go into the screen with the field - done some testing, seems to be becuase of the while do, if i take that out it doesnt freeze but it also doesnt show the correct number of days- so confused :(

Daver262
Posts: 1
Joined: Wed Mar 14, 2018 4:25 pm

Re: Working days to include bank holidays

Post by Daver262 » Mon Sep 09, 2019 11:48 am

Hi

This code works fine. I wanted to calculate 22 working days from the date the letter of claim was sent and put the result into another field.. Just change N-days and your fields to suit :-)

Dave

Code: Select all

# ======================DEC 2010 =========================== 
# Calculate the proposed date by reference to the date field 
# contents and a number of days forward of that date 
# If the date then falls on a weekend or bank holiday move the 
# date forward until it is a valid date 
# Calculate a date a number of working days ahead of the original date 
# ================================================== 
# 
n-date = {Date LOC Sent.Date} 
n-days = 22 [/b]
# 
v-days = DAYS-FROM-TODAY( {Date LOC Sent.Date} ) 
WHILE n-days > 0 DO 
    # 
    # =========================== 
    # Start - set loop and calculate date 
    # =========================== 
    v-days = v-days + 1 
    input-date = DATE-FROM-TODAY( v-days ) 
    PUT( input-date , {Disclosure date.Date} ) 
    v-week = WEEKDAY( v-date ) 
    result = "" 
    input-day = DAY( input-date ) 
    input-month = MONTH( input-date ) 
    input-year = YEAR( input-date ) 
    # 
    # ========== 
    # Check date 
    # ========== 
    # ============= 
    # Special Holidays 
    # ============= 
    IF input-date = "04/06/2012" THEN 
        result = "Moved spring bank holiday"  
    ELSEIF input-date = "05/06/2012" THEN 
        result = "Queens diamond jubilee"  
    ELSEIF input-date = "29/04/2011" THEN 
        result = "Royal Wedding" 
    END 
    n-weekday = WEEKDAY( input-date ) 
    IF n-weekday = "Saturday" THEN 
        result = "Saturday"  
    ELSEIF n-weekday = "Sunday" THEN 
        result = "Sunday"  
    ELSE 
        # =================== 
        # Check for bank holidays 
        # =================== 
        # 
        IF result = "" THEN 
            # ======== 
            # New Year 
            # ======== 
            IF input-month = 1 THEN 
                # 
                new-year = DATE( "01" , "01" , input-year ) 
                new-year-day = WEEKDAY( new-year ) 
                IF new-year-day = "Saturday" THEN 
                    new-year = DATE( "03" , "01" , input-year )  
                ELSEIF new-year-day = "Sunday" THEN 
                    new-year = DATE( "02" , "01" , input-year ) 
                END 
                new-year = TEXT( new-year ) 
                input-date = TEXT( input-date ) 
                IF new-year = input-date THEN 
                    result = "New Years Day" 
                END 
            END 
        END 
        # 
        IF result = "" THEN 
            # =================== 
            # Easter - the difficult one 
            # =================== 
            IF input-month = 3 OR input-month = 4 THEN 
                e-calc = input-year / 19 
                e-rem = e-calc MOD 1 
                e-mult = e-calc - e-rem 
                e-whole = e-mult * 19 
                e-gold = input-year - e-whole + 1 
                e-gold = e-gold + 1 
                e-date = LISTITEM( "2703,1404,0304,2303,1104,3103,1804,0804,2803,1604,0504,2503,1304,0204,2203,1004,3003,1704,0704,2703" , e-gold , "," ) 
                e-day = SPLIT( e-date , 1 , 2 ) 
                e-month = SPLIT( e-date , 3 , 2 ) 
                ev-date = DATE( e-day , e-month , input-year ) 
                the-day = WEEKDAY( ev-date ) 
                e-week-days = "Saturday,Friday,Thursday,Wednesday,Tuesday,Monday,Sunday" 
                e-add = LISTFIND( e-week-days , the-day , "," ) 
                e-days = DAYS-FROM-TODAY( ev-date ) 
                e-days = e-days + e-add 
                ev-easter = DATE-FROM-TODAY( e-days ) 
                # 
                good-fridaydays = DAYS-FROM-TODAY( ev-easter ) - 2 
                good-friday = DATE-FROM-TODAY( good-fridaydays ) 
                easter-mondaydays = DAYS-FROM-TODAY( ev-easter ) + 1 
                easter-monday = DATE-FROM-TODAY( easter-mondaydays ) 
                good-friday = TEXT( good-friday ) 
                easter-monday = TEXT( easter-monday ) 
                input-date = TEXT( input-date ) 
                IF input-date = good-friday THEN 
                    result = "Good Friday"  
                ELSEIF input-date = easter-monday THEN 
                    result = "Easter Monday" 
                END 
            END 
        END 
        # 
        IF result = "" THEN 
            # ======== 
            # Early May 
            # ======== 
            IF input-month = 5 THEN 
                may-first = DATE( "01" , "05" , input-year ) 
                may-weekday = WEEKDAY( may-first ) 
                IF may-weekday <> "Monday" THEN 
                    day-add = LISTFIND( "Sunday,Saturday,Friday,Thursday,Wednesday,Tuesday" , may-weekday , "," ) 
                    may-days-number = DAYS-FROM-TODAY( may-first ) + day-add 
                    may-day = DATE-FROM-TODAY( may-days-number )  
                ELSE 
                    may-day = may-first 
                END 
                may-day = TEXT( may-day ) 
                input-date = TEXT( input-date ) 
                IF input-date = may-day THEN 
                    result = "May Day" 
                END 
            END 
        END 
        # 
        IF result = "" THEN 
            # ================ 
            # Spring Bank Holiday 
            # Changed for 2012 
            # Queens Diamond Jubilee 
            # ================ 
            IF input-month = 5 THEN 
                IF input-year <> 2012 THEN 
                    may-end = DATE( "31" , "05" , input-year ) 
                    may-end-weekday = WEEKDAY( may-end ) 
                    IF may-weekday <> "Monday" THEN 
                        day-subtract = LISTFIND( "Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" , may-end-weekday , "," ) 
                        may-end-days-number = DAYS-FROM-TODAY( may-end ) - day-subtract 
                        spring-holiday = DATE-FROM-TODAY( may-end-days-number )  
                    ELSE 
                        spring-holiday = may-end 
                    END 
                    spring-holiday = TEXT( spring-holiday ) 
                    input-date = TEXT( input-date ) 
                    IF input-date = spring-holiday THEN 
                        result = "Spring Bank Holiday" 
                    END 
                END 
            END 
        END 
        # 
        IF result = "" THEN 
            # ================= 
            # August Bank Holiday 
            # ================= 
            IF input-month = 8 THEN 
                august-end = DATE( "31" , "08" , input-year ) 
                august-end-weekday = WEEKDAY( august-end ) 
                IF august-weekday <> "Monday" THEN 
                    day-subtract = LISTFIND( "Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" , august-end-weekday , "," ) 
                    august-end-days-number = DAYS-FROM-TODAY( august-end ) - day-subtract 
                    august-holiday = DATE-FROM-TODAY( august-end-days-number )  
                ELSE 
                    august-holiday = august-end 
                END 
                august-holiday = TEXT( august-holiday ) 
                input-date = TEXT( input-date ) 
                IF input-date = august-holiday THEN 
                    result = "August Bank Holiday" 
                END 
            END 
        END 
        # 
        # 
        IF result = "" THEN 
            # ======== 
            # Christmas 
            # ======== 
            IF input-month = 12 THEN 
                christmas-day = DATE( "25" , "12" , input-year ) 
                boxing-day = DATE( "26" , "12" , input-year ) 
                christmas-weekday = WEEKDAY( christmas-day ) 
                IF christmas-weekday = "Friday" THEN 
                    christmas-day = DATE( "25" , "12" , input-year ) 
                    boxing-day = DATE( "28" , "12" , input-year )  
                ELSEIF christmas-weekday = "Saturday" THEN 
                    christmas-day = DATE( "27" , "12" , input-year ) 
                    boxing-day = DATE( "28" , "12" , input-year )  
                ELSEIF christmas-weekday = "Sunday" THEN 
                    christmas-day = DATE( "26" , "12" , input-year ) 
                    boxing-day = DATE( "27" , "12" , input-year ) 
                END 
                christmas-day = TEXT( christmas-day ) 
                boxing-day = TEXT( boxing-day ) 
                input-date = TEXT( input-date ) 
                IF input-date = christmas-day THEN 
                    result = "Christmas day"  
                ELSEIF input-date = boxing-day THEN 
                    result = "Boxing Day" 
                END 
            END 
        END 
    END 
    # 
    IF result <> "" THEN 
        # 
        # ====================== 
        # Weekend or bank holiday 
        # move date forward one day 
        # then check again 
        # ====================== 
        #  
    ELSE 
        # 
        # =========== 
        # Working day 
        # Reduce loop 
        # to skip a day 
        # =========== 
        n-days = n-days - 1 
        # 
    END 
END 
v-date = DATE-FROM-TODAY( v-days ) 
PUT( v-date , {Disclosure date.Date} )

Post Reply