Asterisk tips openhours

How to include contexts based on time and date

The Asterisk dial plan, extensions.conf lets you include contexts based on time and/or date.


include => <context>,<times>,<weekdays>,<mdays>,<months>


; First, let's do the holidays.
include => holiday,*,*,1,jan
include => holiday,*,*,31,may
include => holiday,*,*,4,jul
include => holiday,*,*,6,sep
include => holiday,17:00-23:59,*,24,nov
include => holiday,*,*,25,nov
include => holiday,17:00-23:59,*,24,dec
include => holiday,*,*,25,dec
include => holiday,17:00-23:59,*,31,dec

; These are the days we're open.
include => day,09:00-19:59,mon-fri,*,*
include => day,10:00-14:59,sat,*,*

; If we're not open, we're closed.
include => night

Example from Troy Settle

I ran into a problem with this. The night context is always included in this scenario, and if the night context contains the same extensions as the day context, Asterisk will continue with the night context if the extensions match:

exten => s,8,BackGround(to-hear-menu-again)

will jump to:
exten => s,9,BackGround()

To prevent this, specify an explicit night include:
include => night,20:00-8:59,mon-fri,*,*
include => night,15:00-9:59,sat,*,*
include => night,*,sun,*,*

Created by: oej, Last modification: Wed 01 of Feb, 2012 (19:59 UTC) by rdailey79
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+