It might be simpler to use the GotoIfTime command in your dial plan, rather than using an AGI script. GotoIfTime is well documented on the asterisk wiki.
Here is a link to the wiki page in question. Don’t duplicate the info since the link should suffice, and you won’t need to update this forum post when the wiki changes due to new functionality/changes in Asterisk.