[mythtv-commits] Ticket #11538: XMLTV date parsing issue

MythTV noreply at mythtv.org
Wed May 15 23:36:25 UTC 2013


#11538: XMLTV date parsing issue
---------------------------------------+-----------------------------
 Reporter:  richard@…                  |          Owner:  stuartm
     Type:  Bug Report - General       |         Status:  new
 Priority:  minor                      |      Milestone:  unknown
Component:  MythTV - Mythfilldatabase  |        Version:  Master Head
 Severity:  medium                     |     Resolution:
 Keywords:  XMLTV                      |  Ticket locked:  0
---------------------------------------+-----------------------------

Comment (by richard@…):

 Ok - I think I know what's going wrong.
 If you give QDateTime::fromString() a string with a zero UTC offset (like
 this: "20130513090000 +0000") the resulting QDateTime object will have a
 Qt::TimeSpec of Qt::LocalTime, so therefore the .toUTC() call will
 incorrectly adjust the date.
 If the string has a non-zero offset (e.g. the same date in localtime -
 "20130513190000 +1000"), the QDateTime object now has a TimeSpec of
 Qt::OffsetFromUTC so the .toUTC() call works correctly.  Personally, I
 think this is a QT defect... we've given it an offset, and it's ignored
 it.  I've reproduced this behaviour with both Qt-4.8 and on my old box
 (Qt-3.3)

 I've attached a standalone sample which illustrates the problem.  If you
 run it with my XMLTV data which is already in UTC (i.e. +0000 offset), the
 result is wrong:
 {{{
 ./date_test "20130513090000 +0000"
 "Parsing: 2013-05-13T09:00:00 +0000"
 "Parsed Result: Mon May 13 09:00:00 2013, TimeSpec: 0"
 "toUTC() Result: Sun May 12 23:00:00 2013, TimeSpec: 1"
 "Localtime QDateTime: Mon May 13 09:00:00 2013"
 }}}

 However, if you give it a date with a non-zero offset - you get the
 correct result:
 {{{
 ./date_test "20130513190000 +1000"
 "Parsing: 2013-05-13T19:00:00 +1000"
 "Parsed Result: Mon May 13 19:00:00 2013, TimeSpec: 2"
 "toUTC() Result: Mon May 13 09:00:00 2013, TimeSpec: 1"
 "Localtime QDateTime: Mon May 13 19:00:00 2013"
 }}}

 Something like this seems to fix it:
 {{{
 *** a/date_test.cpp     2013-05-16 09:16:22.913187091 +1000
 --- b/date_test.cpp     2013-05-16 09:26:12.725426207 +1000
 ***************
 *** 70,75 ****
 --- 70,78 ----
                                                   .arg(tmp);
         qDebug() << QString("Parsing: %1").arg(isoDateString);
         QDateTime dt2 = QDateTime::fromString(isoDateString, Qt::ISODate);
 +       // QT seems to think that zero offset dates are LocalTime - force
 them to UTC
 +       if (dt2.timeSpec() == Qt::LocalTime)
 +           dt2.setTimeSpec(Qt::UTC);
         qDebug() << QString("Parsed Result: %1, TimeSpec:
 %2").arg(dt2.toString()).arg(dt2.timeSpec());
           dt = dt2.toUTC();
         qDebug() << QString("toUTC() Result: %1, TimeSpec:
 %2").arg(dt.toString()).arg(dt.timeSpec());
 }}}

-- 
Ticket URL: <http://code.mythtv.org/trac/ticket/11538#comment:2>
MythTV <http://code.mythtv.org/trac>
MythTV Media Center


More information about the mythtv-commits mailing list