Not a customer? Click the 'Start a free trial' link to begin a 30-day SaaS trial of our product and to join our community.
Existing Cisco AppDynamics customers should click the 'Sign In' button to authenticate to access the community
on 09-25-2023 09:00 AM
Automatically update event timestamps of the events in an email template to align with a specific time zone’s daylight-saving time changes.
SaaS customers rely on the time zone configured in the Controller to determine the offset between their local time zone and the one used by the Controller. Therefore, you need to manually modify the timestamp value in each template (email or HTTP) and keep it updated according to whether daylight saving is active or not.
Using an automatic script rather than relying on a manual process to update the timestamp value eliminates potential update gaps for twice-yearly daylight-saving time updates.
If daylight-saving time is active, customers need to manually update the timestamp value, which can be error-prone and requires being done twice a year.
While this solution implements automated updates for US daylight saving time, you can use it as a template for daylight saving schedules in any other country.
In the US:
The code currently works for full-hour offsets, but it can be updated to work with partial-hour offsets.
This implementation considers that the SaaS controller is using the UTC time zone.
Daylight Savings is applied during December, January, and February.
Then, modify the time zone acronym from UTC to the local acronym.
NOTE | the code is using $latestEvent.eventTime as initial time value
NOTE | The index of the months and weekdays are zero based, so January is index 0 and December is index 11, and the week starts on Sunday with 0 and ends on Saturday with 6.
NOTE | If required, delete all comments.
## Variable declaration #set($date = $latestEvent.eventTime) #set($month = $date.getMonth()) #set($day = $date.getDate()) #set($weekDay = $date.getDay())
## By default, the offset is applied to the hours variable #set ($newHours = ${date.getHours()} - $offset) #set($daylightSavingOffset = $offset + 1)
## In the months of January, February, and December, the daylight-saving time is applied #if($month == 11 || $month == 0 || $month == 1) #set($newHours = ${date.getHours()} - $daylightSavingOffset) #end
## In the month of October, it is required to find the first Sunday of the month to verify if the daylight saving time needs to be applied #if($month == 10) #set($tempDate = $latestEvent.eventTime) #set($firstSunday = $weekDay)
## Loop through the first 8 days of the month to find the first Sunday of the month #foreach($tempDay in [1..8]) $tempDate.setDate($tempDay) #set($tempWeekDay = $tempDate.getDay())
## If the current day we are looping is Sunday we store that day and break the loop #if($tempWeekDay == 0) #set($firstSunday = $tempDay) #break #end #end
## If the current day is after the first Sunday of October, the daylight-saving time is applied #if($day > $firstSunday) #set($newHours = ${date.getHours()} - $daylightSavingOffset) ## If the current day is the first Sunday of Octuber, the daylight-saving time is only applied if the current hour is or has passed 2:00 a.m #elseif($day == $firstSunday && $newHours >= 2) #set($newHours = ${date.getHours()} - $daylightSavingOffset) #end #end
## In the month of March, it is required to find the second Sunday of the month to verify if the daylight-saving time needs to be applied #if($month == 2) #set($tempDate = $latestEvent.eventTime) #set($secondSunday = $weekDay)
## Variable use to count the number of Sundays that have been looped #set($counter = 0)
## Loop through the first 15 days of the month to find the second Sunday of the month #foreach($tempDay in [1..15]) $tempDate.setDate($tempDay) #set($tempWeekDay = $tempDate.getDay())
## If the current day we are looping is Sunday we need to increase the counter if looped Sundays #if($tempWeekDay == 0) #set($counter = $counter + 1)
## If the number of looped Sundays is 2, it means that the second Sunday of the month has been found, the day is stored, and the loop stopped #if($counter == 2) #set($secondSunday = $tempDay) #break #end #end #end
## If the current day is before the second Sunday of March, the daylight-saving time is applied #if($day < $secondSunday) #set($newHours = ${date.getHours()} - $daylightSavingOffset) ## If the current day is the second Sunday of March, the daylight-saving time is only applied if the current hour has not passed 2:00 a.m #elseif($day == $secondSunday && $newHours < 2) #set($newHours = ${date.getHours()} - $daylightSavingOffset) #end #end ## Generate the new date using the new hours with the offset $date.setHours(${newHours}) #set ($dateString =${date.toString()}) ## Change the timezone acronym #set ($replacedDateString=${dateString.replace('UTC',$localTZ)}) |
Thank you! Your submission has been received!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form