mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-14 09:58:17 +00:00
switch_utils: Add time of day string compare function switch_tod_cmp. It usable in XML dialplan with time-of-day. String format is hh:mm:ss you can define a range like this : 09:00-17:00 (Second are not optional)
This commit is contained in:
@@ -2662,6 +2662,7 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond) {
|
||||
const char *xhour = switch_xml_attr(xcond, "hour");
|
||||
const char *xminute = switch_xml_attr(xcond, "minute");
|
||||
const char *xminday = switch_xml_attr(xcond, "minute-of-day");
|
||||
const char *xtod = switch_xml_attr(xcond, "time-of-day");
|
||||
|
||||
switch_time_t ts = switch_micro_time_now();
|
||||
int time_match = -1;
|
||||
@@ -2747,6 +2748,15 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond) {
|
||||
"XML DateTime Check: minute of day[%d] =~ %s (%s)\n", test, xminday, time_match ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
if (time_match && xtod) {
|
||||
int test = (tm.tm_hour * 60 * 60) + (tm.tm_min * 60) + tm.tm_sec;
|
||||
char tmpdate[10];
|
||||
switch_snprintf(tmpdate, 6, "%d:%d:%d", tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
time_match = switch_tod_cmp(xtod, test);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9,
|
||||
"XML DateTime Check: time of day[%s] =~ %s (%s)\n", tmpdate, xtod, time_match ? "PASS" : "FAIL");
|
||||
}
|
||||
|
||||
return time_match;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user