]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
xmltv: Handle substring timestamps. (#4594)
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Sun, 19 Nov 2017 13:32:39 +0000 (13:32 +0000)
committerJaroslav Kysela <perex@perex.cz>
Thu, 23 Nov 2017 08:00:38 +0000 (09:00 +0100)
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.

src/epggrab/module/xmltv.c

index f02b6c1ea0449d17ea3bb208081be16871a7755e..d62f810075ec9b88bf419e2a5dd3f5ba9bf1485b 100644 (file)
@@ -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;