Macro optimization

Re-halllo :wink:

I have a little dialplan for my office with holiday and open time, it’s fully functional but i don’t like the line in red, for me these is a more efficent solution…

Any idea???


exten => s,1,GotoIfTime(||1-6|jan?fuori-orario,s,1)
exten => s,n,GotoIfTime(||1|may?fuori-orario,s,1)
exten => s,n,GotoIfTime(||25|apr?fuori-orario,s,1)
exten => s,n,GotoIfTime(||2|jun?fuori-orario,s,1)
exten => s,n,GotoIfTime(||15|aug?fuori-orario,s,1)
exten => s,n,GotoIfTime(||1|nov?fuori-orario,s,1)
exten => s,n,GotoIfTime(||8|dec?fuori-orario,s,1)
exten => s,n,GotoIfTime(||25-26|dec?fuori-orario,s,1)
exten => s,n,GotoIfTime(||31|dec?fuori-orario,s,1)
exten => s,n,Set(MACRO_PRIORITY=$[${MACRO_PRIORITY} + 1])

[color=red]exten => s,n,GotoIfTime(9:00-12:30|mon-sat||?${MACRO_CONTEXT},${MACRO_EXTEN},${MACRO_PRIORITY})

exten => s,n,GotoIfTime(15:00-20:30|mon-fri||?${MACRO_CONTEXT},${MACRO_EXTEN},${MACRO_PRIORITY})
exten => s,n,Goto(fuori-orario,s,1)
exten => s,n,Hangup()

[in-gil] ;ingresso da eutelia

exten => s,1,Answer()
exten => s,n,Macro(festivi)
exten => s,n,Dial(SIP/210,30,tTrR)
exten => s,n,Playback(vm-login)
exten => s,n,Playback(vm-intro)
exten => s,n,VoiceMail(210@testmail)
exten => s,n,PlayBack(vm-goodbye)
exten => s,n,Hangup()

TNX, Manuel 8)

What exactly is unlikable here?:? Looks extremely efficient to me in terms of algorithm. If the entire macro is quoted, the only “improvement” I can think of would be to not meddle with MACRO_PRIORITY. (A bit surprised that such are not read-only.) Instead, use a local variable

[code]exten => s,n,Set(BACK=${MACRO_CONTEXT},${MACRO_EXTEN},$[${MACRO_PRIORITY} + 1])
exten => s,n,GotoIfTime(9:00-12:30|mon-sat||?${BACK})

exten => s,n,GotoIfTime(15:00-20:30|mon-fri||?${BACK})

(Depending on the version, you may want to double quote the string assigned to BACK.) Note there is no efficiency improvement in the above.

Ok! It was just what I searching in order to slim a little bit the sequence :wink:

After a “fewâ€

Mark Spencer’s Asterisk Manual points to another (cleaner) possible approach (untested):

exten => s,n,Set(MACRO_OFFSET=1) exten => s,n,GotoIfTime(9:00-12:30|mon-sat|*|*?back,1) exten => s,n,GotoIfTime(15:00-20:30|mon-fri|*|*?back,1) exten => back,1,NoOp

The idea is that the macro will exit to ${MACRO_PRIORITY} + ${MACRO_OFFSET}. Not sure if NoOp is the cleanest method to exit, though.