refactor switch_fulldate_cmp and correct usec comparison and year month error

This commit is contained in:
Jeff Lenk 2012-01-01 22:40:23 -06:00
parent 2b904c0b9e
commit 79992ac5fe
1 changed files with 10 additions and 13 deletions

View File

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