From a13f3b81190ef0306967e17f696346fe1ab7f13e Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Thu, 11 Oct 2012 11:04:54 +0100 Subject: [PATCH] Fix problems with XMLTV time processing. --- src/epggrab/module/xmltv.c | 40 +++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c index 83d05047..18c53ef8 100644 --- a/src/epggrab/module/xmltv.c +++ b/src/epggrab/module/xmltv.c @@ -59,28 +59,46 @@ static epggrab_channel_t *_xmltv_channel_find /** * */ -static time_t _xmltv_str2time(const char *str) +static time_t _xmltv_str2time(const char *in) { struct tm tm; - int tz, r; + int tz = 0, r; + int sp = 0; + char str[32]; memset(&tm, 0, sizeof(tm)); + strcpy(str, in); - r = sscanf(str, "%04d%02d%02d%02d%02d%02d %d", + /* split tz */ + while (str[sp] && str[sp] != ' ') + sp++; + + /* parse tz */ + // TODO: handle string TZ? + if (str[sp]) { + sscanf(str+sp+1, "%d", &tz); + tz = (tz % 100) + (tz / 100) * 3600; // Convert from HHMM to seconds + str[sp] = 0; + sp = 1; + } else { + sp = 0; + } + + /* parse time */ + r = sscanf(str, "%04d%02d%02d%02d%02d%02d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, - &tm.tm_hour, &tm.tm_min, &tm.tm_sec, - &tz); + &tm.tm_hour, &tm.tm_min, &tm.tm_sec); + /* adjust */ tm.tm_mon -= 1; tm.tm_year -= 1900; tm.tm_isdst = -1; - tz = (tz % 100) + (tz / 100) * 60; // Convert from HHMM to minutes - - if(r == 6) { - return mktime(&tm); - } else if(r == 7) { - return timegm(&tm) - tz * 60; + if (r >= 5) { + if(sp) + return timegm(&tm) - tz; + else + return mktime(&tm); } else { return 0; }