Search:
     
3CX Phone System for Windows Download the Free Edition

Asterisk cmd GotoIfTime

Synopsis:

 Conditional goto on current time

Description:

 GotoIfTime(<time range>|<days of week>|<days of month>|<months>?[[context|]extension|]pri)

Asterisk 1.6
 GotoIfTime(<time range>,<days of week>,<days of month>,<months>?[[context,]extension,]pri)

Note: Asterisk 1.6 do not support "|" as seperater it now only uses ","

If the current time matches the specified time, then branch to the specified extension. Each of the elements may be specified either as '*' (for always) or as a range. If the current time does not match the specified time, next priority is executed.

Times before Asterisk 1.6.2 are only accurate down to the 2-minute interval. So 12:01 is treated the same as 12:00.
Starting with 1.6.2, times are accurate down to the minute.

How to specify time

The include syntax is defined in the sample extensions.conf like this:

 <time range>|<days of week>|<days of month>|<months>

where:
         <time range>= <hour>':'<minute>'-'<hour>':'<minute> 
                       | "*"
         <days of week> = <dayname>
                       |  <dayname>'-'<dayname>
                       | "*"
         <dayname> = "sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat"
         <days of month> = <daynum>
                        |  <daynum>'-'<daynum>
                        | "*"
         <daynum> = a number, 1 to 31, inclusive
         <hour> = a number, 0 to 23, inclusive
         <minute> = a number, 0 to 59, inclusive
         <months> = <monthname>
                    | <monthname>'-'<monthname>
                    | "*"
         <monthname> = "jan" | "feb" | "mar" | "apr" | "may" | "jun" | "jul" | "aug" | "sep" | "oct" | "nov" | "dec"

daynames and monthnames are not case-sensitive.
  

Examples

If you replace an option with *, it is ignored when matching. For instance:

 exten => 3000,1,GotoIfTime(9:00-17:00|mon-fri|*|*?open,s,1)

would transfer to context "open", extension s, priority 1 if it's between 9:00 and 17:00, Monday through Friday, not checking the day of month or month.

Another example:

 exten => s,6,GotoIfTime(*|*|26-30|May?attendant,s,30)

would transfer to context "attendant", extension s, priority 30 at any time from May 26th though May 30th. (In this example, an office is closed for Memorial Day.)


Holidays


If the comment about holidays are true, then here's a list suitable in The United States:

   Independence Day:         *|*|4|jul
   Christmas:                *|*|25|dec
   NewYear:                  *|*|1|jan
   MartinLutherKing:         *|mon|15-21|jan
   Valentines:               *|*|14|feb
   StPatDay                  *|*|17|mar
   Halloween                 *|*|31|oct
   Thanksgiving              *|thu|22-28|nov
   MemorialDay               *|mon|25-31|may
   LaborDay                  *|mon|1-7|sep
   Pres/WashBday             *|mon|15-21|feb
   MothersDay                *|sun|8-14|may
   FathersDay                *|sun|15-21|jun

Easter: Good Luck! Paschal moons, etc).
                    2007  *|*|8|apr
                    2008  *|*|23|mar
                    2009  *|*|12|apr
                    2010  *|*|4|apr
                    2011  *|*|24|apr
                    2012  *|*|8|apr
                    2013  *|*|31|mar
                    2014  *|*|20|apr
                    2015  *|*|5|apr
                    2016  *|*|27|mar
                    2017  *|*|16|apr
                    2018  *|*|1|apr
                    2019  *|*|21|apr
                    2020  *|*|12|apr
                    2021  *|*|4|apr
                    2022  *|*|17|apr
                    2023  *|*|9|apr
                    2024  *|*|31|mar
                    2025  *|*|20|apr
                    2026  *|*|5|apr
                    2027  *|*|28|mar
                    2028  *|*|16|apr
                    2029  *|*|1|apr
                    2030  *|*|21|apr
                    2031  *|*|13|apr
                    2032  *|*|28|mar
                    2033  *|*|17|apr
                    2034  *|*|9|apr
                    2035  *|*|25|mar
                    2036  *|*|13|apr
                    2037  *|*|5|apr
                    2038  *|*|25|apr
                    2039  *|*|10|apr

Here is the calculation of Easter dates:
http://www.oremus.org/liturgy/etc/ktf/app/easter.html


No years - How do I do this without reprogramming every year?

If the day in question is always in the same month, and moves not more than 7 days (e.g. in New Zealand, Labour day is "the fourth monday in October"), you can specify a perpetual version; work out the earliest and the latest it can be, and specify the necessary weekday. The fourth Monday can not be earlier than the 22nd and not later than the 28th. So:

GotoIfTime(*,mon,22-28,oct?labourday,s,1);

Similarly, if it is the sort of holiday that moves to Monday if it falls on the weekend, you can do it with a couple of rules. For example, in New Zealand, "New Years Day" is the 1st of January (if the first of January is a weekday) or the first weekday thereafter:

GotoIfTime(*,mon-fri,1,jan?happynewyears,s,1);
GotoIfTime(*,mon,2-3,jan?happynewyears,s,1);

- that is, the 1st of January if it's a weekday, or the monday on the second or third of January.

Easter is a lot more complicated.

Using GotoIfTime for non-static dates (for example, UK bank holidays in my case) means that the system must be updated every year. If the person who knows that this must be done forgets (or is no longer associated with the phone system) then things can go horribly wrong.
So.... For UK bank holidays, run the following script (which contains all UK bank holidays up to the end of 2009):

  1. !/bin/sh
asterisk -rx 'database deltree bankholiday'
asterisk -rx 'database put bankholiday 20060828 1'
asterisk -rx 'database put bankholiday 20061225 1'
asterisk -rx 'database put bankholiday 20061226 1'
asterisk -rx 'database put bankholiday 20070101 1'
asterisk -rx 'database put bankholiday 20070406 1'
asterisk -rx 'database put bankholiday 20070409 1'
asterisk -rx 'database put bankholiday 20070507 1'
asterisk -rx 'database put bankholiday 20070528 1'
asterisk -rx 'database put bankholiday 20070827 1'
asterisk -rx 'database put bankholiday 20071225 1'
asterisk -rx 'database put bankholiday 20071226 1'
asterisk -rx 'database put bankholiday 20080101 1'
asterisk -rx 'database put bankholiday 20080321 1'
asterisk -rx 'database put bankholiday 20080324 1'
asterisk -rx 'database put bankholiday 20080505 1'
asterisk -rx 'database put bankholiday 20080526 1'
asterisk -rx 'database put bankholiday 20080825 1'
asterisk -rx 'database put bankholiday 20081225 1'
asterisk -rx 'database put bankholiday 20081226 1'
asterisk -rx 'database put bankholiday 20090101 1'
asterisk -rx 'database put bankholiday 20090410 1'
asterisk -rx 'database put bankholiday 20090413 1'
asterisk -rx 'database put bankholiday 20090504 1'
asterisk -rx 'database put bankholiday 20090525 1'
asterisk -rx 'database put bankholiday 20090831 1'
asterisk -rx 'database put bankholiday 20091225 1'
asterisk -rx 'database put bankholiday 20091228 1'
exit


and then use the following in your dialplan:

exten => s,n,Set(BANKHOLIDAY=${DB_EXISTS(bankholiday/${TIMESTAMP:0:8})})


Same as above for asterisk >1.4 cause ${TIMESTAMP} is deprecated
exten => s,n,Set(BANKHOLIDAY=${DB_EXISTS(bankholiday/${STRFTIME(${EPOCH},,%Y%m%d)})})

${BANKHOLIDAY} will now be either '0' or '1' and this can be used to do your GotoIf's on!



See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Created by: oej,Last modification on Mon 01 of Nov, 2010 [02:26 UTC] by JustRumours


Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

 





Search: