]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
refactor switch_fulldate_cmp and correct usec comparison and year month error
authorJeff Lenk <jeff@jefflenk.com>
Mon, 2 Jan 2012 04:40:23 +0000 (22:40 -0600)
committerJeff Lenk <jeff@jefflenk.com>
Mon, 2 Jan 2012 04:40:23 +0000 (22:40 -0600)
src/switch_utils.c

index 4624badc074b925a52933a2300b59a839ae8da37..808afd0c571a89c9127e35401e06c7ce04592fb8 100644 (file)
@@ -2342,6 +2342,9 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts)
        char *sTime;
        switch_time_t tsStart;
        switch_time_t tsEnd;
+       struct tm tmTmp;
+       int year, month, day;
+       int hour, min, sec;
 
        switch_assert(dup);
 
@@ -2350,16 +2353,13 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts)
                *sEnd++ = '\0';
                sDate = sStart;
                if ((sTime=strchr(sStart, ' '))) {
-                       struct tm tmTmp;
-                       int year, month, day;
-                       int hour, min, sec;
-
                        *sTime++ = '\0';
 
+                       memset(&tmTmp, 0, sizeof(tmTmp));
                        switch_split_date(sDate, &year, &month, &day);
                        switch_split_time(sTime, &hour, &min, &sec);
-                       tmTmp.tm_year = year;
-                       tmTmp.tm_mon = month;
+                       tmTmp.tm_year = year-1900;
+                       tmTmp.tm_mon = month-1;
                        tmTmp.tm_mday = day;
 
                        tmTmp.tm_hour = hour;
@@ -2370,16 +2370,13 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts)
 
                        sDate = sEnd;
                        if ((sTime=strchr(sEnd, ' '))) {
-                               struct tm tmTmp;
-                               int year, month, day;
-                               int hour, min, sec;
-
                                *sTime++ = '\0';
 
+                               memset(&tmTmp, 0, sizeof(tmTmp));
                                switch_split_date(sDate, &year, &month, &day);
                                switch_split_time(sTime, &hour, &min, &sec);
-                               tmTmp.tm_year = year;
-                               tmTmp.tm_mon = month;
+                               tmTmp.tm_year = year-1900;
+                               tmTmp.tm_mon = month-1;
                                tmTmp.tm_mday = day;
 
                                tmTmp.tm_hour = hour;
@@ -2388,7 +2385,7 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts)
                                tmTmp.tm_isdst = 0;
                                tsEnd = mktime(&tmTmp);
 
-                               if (tsStart <= *ts && tsEnd > *ts) {
+                               if (tsStart <= *ts/1000000 && tsEnd > *ts/1000000) {
                                        switch_safe_free(dup);
                                        return 1;
                                }