To implement a day and night mode in your Asterisk dialplan, you can use the GotoIfTime dialplan function to branch to different sections of the dialplan based on the current time.
For example, you can use the following dialplan to route calls to different destinations depending on whether it is currently day or night:
[daynight]
exten => s,1,GotoIfTime(08:00-19:00,day,night)
[day]
exten => s,1,Dial(SIP/office-phone)
exten => s,n,Hangup()
[night]
exten => s,1,Dial(SIP/mobile-phone)
exten => s,n,Hangup()
This dialplan will route calls to the day context if it is between 8:00 AM and 7:59 PM, and to the night context if it is outside of this time range. In the day context, the call will be dialed to the office-phone, and in the night context, the call will be dialed to the mobile-phone.
You can also use the GotoIfTime function to specify multiple time ranges and destinations. For example:
[daynight]
exten => s,1,GotoIfTime(08:00-12:00,morning,13:00-19:00,afternoon,night)
[morning]
exten => s,1,Dial(SIP/office-phone)
exten => s,n,Hangup()
[afternoon]
exten => s,1,Dial(SIP/office-phone)
exten => s,n,Hangup()
[night]
exten => s,1,Dial(SIP/mobile-phone)
exten => s,n,Hangup()
This dialplan will route calls to the morning context if it is between 8:00 AM and 11:59 AM, to the afternoon context if it is between 12:00 PM and 7:59 PM, and to the night context if it is outside of these time ranges.
You can find more information about the GotoIfTime function and other dialplan functions in the Asterisk documentation.