]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add Vagabond's week of year patch
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 30 Nov 2009 16:23:42 +0000 (16:23 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 30 Nov 2009 16:23:42 +0000 (16:23 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15721 d0543943-73ff-0310-b7d9-9358b9ac24b2

conf/dialplan/default.xml
src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c

index dcd3fbd9367092c6331790a108eb8d0a3d3bd72b..5e25a2317a8e8438cc6c57e415a2559771a763f6 100644 (file)
@@ -27,6 +27,7 @@
         mon = 1-12
         mday = 1-31
         week = 1-52
+        mweek= 1-6
         wday = 1-7
         hour = 0-23
         minute = 0-59
     <extension name="tod_example" continue="true">
       <condition wday="2-6" hour="9-18">
        <action application="set" data="open=true"/>
+      </condition>
+               </extension>
+
+    <!-- Example of routing based on holidays
+
+       This example covers all US Federal holidays except for inauguration day and memorial day.
+    -->
+
+    <extension name="holiday_example" continue="true">
+      <condition mday="1" mon="1">
+       <!-- new year's day -->
+       <action application="set" data="open=false"/>
+      </condition>
+      <condition wday="2" mweek="3" mon="1">
+       <!-- martin luther king day is the 3rd monday in january -->
+       <action application="set" data="open=false"/>
+      </condition>
+      <condition wday="2" mweek="3" mon="2">
+       <!-- president's day is the 3rd monday in february -->
+       <action application="set" data="open=false"/>
+      </condition>
+      <condition mday="4" mon="6">
+       <!-- independence day -->
+       <action application="set" data="open=false"/>
+      </condition>
+      <condition wday="2" mweek="1" mon="9">
+       <!-- labor day is the 1st monday in september -->
+       <action application="set" data="open=false"/>
+      </condition>
+      <condition wday="2" mweek="2" mon="10">
+       <!-- columbus day is the 2st monday in october -->
+       <action application="set" data="open=false"/>
+      </condition>
+      <condition mday="11" mon="11">
+       <!-- veteran's day -->
+       <action application="set" data="open=false"/>
+      </condition>
+      <condition wday="5-6" mweek="4" mon="11">
+       <!-- thanksgiving is the 4th thursday in november and usually there's an extension for black friday -->
+       <action application="set" data="open=false"/>
+      </condition>
+      <condition mday="25" mon="12">
+       <!-- Christmas -->
+       <action application="set" data="open=false"/>
       </condition>
     </extension>
 
index 55eb23453c3de5c22c2424898951c03c0ff24834..cf6a7a9e7927a1ae54412d62a463f4e6d05801a7 100644 (file)
@@ -106,6 +106,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
                const char *xmon = switch_xml_attr(xcond, "mon");
                const char *xmday = switch_xml_attr(xcond, "mday");
                const char *xweek = switch_xml_attr(xcond, "week");
+               const char *xmweek = switch_xml_attr(xcond, "mweek");
                const char *xwday = switch_xml_attr(xcond, "wday");
                const char *xhour = switch_xml_attr(xcond, "hour");
                const char *xminute = switch_xml_attr(xcond, "minute");
@@ -160,6 +161,16 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
                                                          "Dialplan: week of year[%d] =~ %s (%s)\n", test, xweek, time_match ? "PASS" : "FAIL");
                }
 
+               if (time_match && xmweek) {
+                       /* calculate the day of the week of the first of the month (0-6) */
+                       int firstdow = (int) (7 - (tm.tm_mday - (tm.tm_wday + 1)) % 7) % 7;
+                       /* calculate the week of the month (1-6)*/
+                       int test = (int) ceil((tm.tm_mday + firstdow) / 7.0);
+                       time_match = switch_number_cmp(xmweek, test);
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
+                                                         "Dialplan: week of month[%d] =~ %s (%s)\n", test, xmweek, time_match ? "PASS" : "FAIL");
+               }
+
                if (time_match && xwday) {
                        int test = tm.tm_wday + 1;
                        time_match = switch_number_cmp(xwday, test);