[mythtv] MythTV UTC branch merge

danielk danielk at cuymedia.net
Wed Jun 6 01:11:39 UTC 2012


On 06/05/2012 08:02 PM, Jean-Yves Avenard wrote:
> Does this all work with qt 4.6 yet??
>
> Last I used some code dealing with UTC time, it was often using
> functions only available from qt 4.7.  The details are blurry in my
> memory so I was just wondering if this merge meant a qt bump...

No Qt bump required. The useful new functions in QDateTime are
more to do with how you initialize and use millisecond accurate
QDateTime objects. With Qt 4.6 and earlier this can be a very
tedious process. But dealing with UTC vs localtime is pretty
simple even with older Qt versions.

There are basically two methods you need to know about for
most things: QDateTime::toUTC() and QDateTime::toLocalTime()
These will convert to UTC and to local time as long as the
"timespec" property of the QDateTime is set properly. When
looking at a date coming from Qt sources the timespec will
always be set properly. When coming from the database we
can use the MythDate::as_utc() around the QDateTime for it's
timespec to be set properly; and with a UTC string
MythDate::fromString() will ensure the timespec is set.
mythdate.cpp is only 150 lines and takes care of almost all
the cases.

For converting QDateTime objects to strings MythDate::toString()
Provides all the formats we use and is smart enough to know
that if you don't specify that you want local time or UTC it
will use local time for human friendly formats and UTC for
computer friendly formats.

-- Daniel


More information about the mythtv-dev mailing list