Determining non-business hours i.e. late evenings and/or weekends



Determine if the notification is triggered within business hours or not. Based upon the response of the script, appropriate template can be sent to the client to confirm user's availability. 

The only variables you should modify are: 

  • businessDays (line 2)

  • businessHours (line 3)

  • TimeZone (line 9)



##Variable declaration #set ( $businessDays = [ "Mon", "Tue", "Wed", "Thur", "Fri" ] ) #set ( $businessHours = [ "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18" ] ) #set ( $outOfBusinessDays = true ) #set ( $outOfBusinessHours = true ) #set ( $counterA = 0 ) #set ( $counterB = 0 ) ##For more information on TimeZone, please visit https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html #set ( $london = $jemhUtils.getTimeZone("GMT+5:30") ) #set ( $myTime = $dateFormatter.withZone( $london ).format( $jemhDateUtils.createDate($currentMillis.longValue() ) ) ) #set ( $currentDate = $dateFormatter.parse($myTime) ) ##Further conversion to String variable #set ( $timestampStr = $currentDate.toString() ) ##Spit the timeStamp into array to loop through #set ( $splitSpaceParts = $timestampStr.split(" ") ) #foreach ($timeComponent in $splitSpaceParts) ##counterA represents the first item in the list which is the day (in short format) #if( $counterA == 0 ) ##if today's day matches what we have in our $businessDays list means that it's not out of business days #if ( $businessDays.contains($timeComponent) ) #set ( $outOfBusinessDays = false ) #end ##counterA value 3 reperesents the time in the date which will be used to determine out of hours variable #elseif ( $counterA == 3 ) ##Now we split the time to extract the hours (ignoring the minutes and seconds) #set ( $splitPartAgain = $timeComponent.split(":") ) #foreach( $timeComponentHour in $splitPartAgain ) ##counterB 0 values determines the first value in the array with is hours #if( $counterB == 0 ) ##if the hours value match what we've specified in $businessHours - means that we are in business hours #if ( $businessHours.contains($timeComponentHour) ) #set ( $outOfBusinessHours = false ) #end #end #set ( $counterB = $counterB + 1) #end #end #set ($counterA = $counterA + 1) #end #if ( $outOfBusinessDays) ##If it's Saturday or Sunday #**#Thank you for your email! #**#Unfortunately, we are currently not available to answer any queries at this moment as the office is shut right now. Your query will be addressed on the next working day from now. #**#Sincere apologies for causing any inconvience. #**#Best regards, #**#-Support Team- ##Otherwise it's a weekday #else #if ( $outOfBusinessHours ) ##If it's outside of office hours #* *#Thank you for your email! #* *#Unfortunately, we are currently not available to answer any queries at this moment as the office is shut right now. Your query will be addressed on the next working day from now. #* *#Sincere apologies for causing any inconvience. #* *#Best regards, #* *#-Support Team- #else #* *#Thank you for your email! #* *#The support team has receieved your query and are now working on it. #* *#You'll be updated as soon as the support team has any questions or make any progress on your query. #* *#Best regards, #* *#-Support Team- #end #end



Output (in preview mode):