From: E.Smith <31170571+azlm8t@users.noreply.github.com> Date: Sun, 19 Nov 2017 13:32:39 +0000 (+0000) Subject: xmltv: Handle substring timestamps. (#4594) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80cd324225dd6da72b2dae5fbff6229867676274;p=thirdparty%2Ftvheadend.git xmltv: Handle substring timestamps. (#4594) The DTD spec says that timestamps can be substrings. These are typically used when specifying a previously-shown date where it only has they YYYYMMDD and not the HHMMSS. So we now parse these correctly which ensures we correctly set the previously shown timestamp. Issue: #4594. --- diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c index f02b6c1ea..d62f81007 100644 --- a/src/epggrab/module/xmltv.c +++ b/src/epggrab/module/xmltv.c @@ -60,6 +60,7 @@ static time_t _xmltv_str2time(const char *in) char str[32]; memset(&tm, 0, sizeof(tm)); + tm.tm_mday = 1; /* Day is one-based not zero-based */ strncpy(str, in, sizeof(str)); str[sizeof(str)-1] = '\0'; @@ -82,12 +83,19 @@ static time_t _xmltv_str2time(const char *in) &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec); - /* adjust */ - tm.tm_mon -= 1; - tm.tm_year -= 1900; + /* Time "can be 'YYYYMMDDhhmmss' or some initial substring...you can + * have 'YYYYMM'" according to DTD. The imprecise dates are used + * for previously-shown. + * + * r is number of fields parsed (1-based). We have to adjust fields + * if they have been parsed since timegm has some fields based + * differently to others. + */ + if (r > 1) tm.tm_mon -= 1; + if (r > 0) tm.tm_year -= 1900; tm.tm_isdst = -1; - if (r >= 5) { + if (r > 0) { return timegm(&tm) - tz; } else { return 0;