Determine non-business hours in Notification Templates

The ‘Created’ time of an Issue can be used to determine if an issue was created during non-business hours. Using this information, different notifications could be sent depending on business hours. The steps taken to achieve this are as follows:

  1. Find The ‘Created’ Time

    1. Using the Issue Context, find the ‘Created’ field and store its value. See:

      1. https://thepluginpeople.atlassian.net/wiki/spaces/JEMHC/pages/40861735/Manipulate+Webhook+data+in+a+Template

  2. Get the Day and Hour from the ‘Created’ time

    1. Using a $jemhDateUtils.getZonedDateTime() the extracted time can be converted to a ZonedDateTime object which can be used to get the day of the week and hour of day.

  3. Check If the Created time is during office hours

    1. Check that both the Day and Hour are work hours.

  4. Set Email content

    1. If the time is in work hours, send normal email content, otherwise sent our of hours content.

Issue Creation Example

## Variable declaration ## Expeted Bussines Days #set ( $businessDays = [ "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY" ] ) ## expected Bussines hours #set ( $businessHours = [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ] ) #set ( $outOfBusinessDays = true ) #set ( $outOfBusinessHours = true ) ## 1. Find The ‘Created’ Time #set($created = $context.issue.fields.created.asText()) ## 2. Get the Day and Hour from the ‘Created’ time #set($day = $jemhDateUtils.getZonedDateTime($created).getDayOfWeek().name()) #set($hour = $jemhDateUtils.getZonedDateTime($created).getHour()) ## 3. Check If the Created time is during office hours #if ( $businessDays.contains($day) ) #set ( $outOfBusinessDays = false ) #end #if ( $businessHours.contains($hour) ) #set ( $outOfBusinessHours = false ) #end ## 4. Set Email Content ## If either these values are true, the issue was created outside bussines hours #if($outOfBusinessDays || $outOfBusinessHours) ## Out of hours: Put out of hours email content here------------------------ Time is: $hour 'o Clock, on $day Out of Hours #else ## In Bussines hours: Put Normal email content here------------------------ Time is: $hour 'o Clock, on $day Office Open #end

Using Notification time

Using the time the Notification was created rather than the issue creation time allows any notification use different Email content dependant on business hours.This requires a local timezone to be applied to the current time in UTC (Coordinated Universal Time).

  1. Find and Format the Current time

    1. Using $jemhDateUtils.nowDate().toString(), the current time is recorded, this needs to be formatted in an accepted format ("yyyy-MM-dd'T'HH:mm:ss.SSSZ") This format is expected by $jemhDateUtils.getZonedDateTime(). For More info see:

      1. https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

  2. Get the Local Time

    1. The local Time Zone needs to be applied to the current time which is in UTC, see:

      1. https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#getAvailableZoneIds--

  3. Get the Day and Hour from the current local time

  4. Check If the Created time is during office hours

  5. Set Email content

    1. If the time is in work hours, send normal email content, otherwise sent our of hours content.

Notification Time Example

## Variable declaration ## Expeted Bussines Days #set ( $businessDays = [ "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY" ] ) ## expected Bussines hours #set ( $businessHours = [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ] ) #set ( $outOfBusinessDays = true ) #set ( $outOfBusinessHours = true ) ## 1. Find and format the current Time #set($formatted = $dateFormatter.format($jemhDateUtils.nowDate().toString(), "yyyy-MM-dd'T'HH:mm:ss.SSSZ")) #set($formatedZonedUTC = $jemhDateUtils.getZonedDateTime($formatted)) ## 2. Get Time Zone #set($zone = $formatedZonedUTC.getZone()) #set($london = $zone.ofOffset("UTC", $zone).of("Europe/London")) ##Set Local time applying the local timezone to the UTC value #set($localNow = $formatedZonedUTC.withZoneSameInstant($london)) ## 3. get Day and hour #set($day = $localNow.getDayOfWeek().name()) #set($hour = $localNow.getHour()) ## 4. Check If the Created time is during office hours #if ( $businessDays.contains($day) ) #set ( $outOfBusinessDays = false ) #end #if ( $businessHours.contains($hour) ) #set ( $outOfBusinessHours = false ) #end ## 5. Set Email Content ## If either these values are true, the issue was created outside bussines hours #if($outOfBusinessDays || $outOfBusinessHours) ## Out of hours: Put out of hours email content here------------------------ Time is: $hour 'o Clock, on $day Out of Hours #else ## In Bussines hours: Put Normal email content here------------------------ Time is: $hour 'o Clock, on $day Office Open #end