Asterisk/FreePBX Time Conditions with Multiple Time Zones / Daylight Saving

This solution is for older Asterisk/FreePBX installations (v2.11 and below) where the Time Condition module doesn’t have the Time Zone dropdown.

TZThis is based on a bash script which alters MySQL DB values to represent the change in DST.

This script will help you to automate DST changes easily and and have peace of mind about not having to manually change every year.

Scenario:

PABX is for an Australian company which has offices in multiple states. Main office is in NSW which observes daylight saving whereas a branch office is in QLD which does not observe daylight saving. Server time is set for NSW timezone.

Step 1:

Create 2 time groups for QLD office, one for normal and one for when DST is observed by NSW.

QLDQLD-DSTNote down the time group ID’s in this case, QLD-BH is 4 and QLD-BH-DST is 5.

Step 2:

Create the Time Condition, select one the above time groups and note down the ID.TC

Step 3:

Upload checkDST script to /var/lib/asterisk/bin/, change ownership to asterisk and set 0755 permissions.

Step 4:

Modify the values for Asterisk DB (DB name, username and password) accordingly.
Set the time group settings as required (time=x)
Set the Time Condition ID (timeconditions_id=x)
Modify the patterns to match (ex: PDT/PST). In this case AEDT for DST and AEST for standard.

Step 5:

Set below crontab code so that this script will be executed on the first Sunday of the month where daylight saving will change. In our example this will be April and October.

0 3 * apr,oct sunĀ  [ $(date +\%d) -le 07 ] && /var/lib/asterisk/bin/checkDST.sh>/dev/null 2>&1

Step 6:

Sit back and enjoy the show.

 

Script explanation:

So how does this script work? It’s quite simple actually. This script gets today’s date and yesterdays date from the system and compares the date strings if they contain the timezone pattern in a certain order.

The script first checks if we’ve moved into DST from standard i.e. yesterday should be AEST and today is AEDT. If so, switch the time groups and apply the settings.

If above is not matching, then it will check the reveres, set the time group and apply the settings.

Leave a Reply

Your email address will not be published. Required fields are marked *