I've been tasked with creating some call routing rules that are based on the time of day. 3CX (the system we use) provide documentation on how to do this, and I have it working to a degree. However, to get the time they provide this C# snippet which is a method in the call flow designer:
return DateTime.Now.Hour < 9;
This returns true or false, and a condition reads this boolean output, and determines where to send calls based on that output.
I need to edit this code snippet to give me a boolean output based on whether or not is is between 8:00 and 16:30.
I am not a developer - I dabbled in Python ages ago but that is not helping me here.
I'm not even sure if this is valid C# code to begin with, but it does work as-is.
The line in the configuration looks like this:
<ns0:ExecuteCSharpCodeComponent ReturnsValue="True" Code="return DateTime.Now.Hour < 9;" ParameterList="<?xml version="1.0" encoding="utf-16"?><ArrayOfScriptParameter xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />" Description="IsTime0to9" MethodName="IsTime0to9" DebugModeActive="False" x:Name="timeFrom0To9" />
This config line checks if the hour is between 9 and 12:
<ns0:ExecuteCSharpCodeComponent ReturnsValue="True" Code="return DateTime.Now.Hour >= 9 && DateTime.Now.Hour < 12;" ParameterList="<?xml version="1.0" encoding="utf-16"?><ArrayOfScriptParameter xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />" MethodName="IsTime9to12" DebugModeActive="False" x:Name="timeFrom9To12" />
Any input would be welcome.
Thank you
You can't really do this by comparing the amounts of minutes and hours, because in the end you can't write a valid condition, unless you really want to branch it out, which is not that efficient or nice.
This will fail for every time that has more than 30 minutes. I'd recommend using TimeSpan, since you can call for the current time of day by calling DateTime.Now.TimeOfDay.
Or you can just rewrite it into one line