Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This changes the internal representation of time to UTC.
Using UTC rather than localtime makes it possible to record programs during daylight savings time changes without overly complicating the code. Unfortunately, the QDateTime initializers all either set the DateSpec to localtime or they set it do undefined. This means you can not use QDateTime::setTime_t(), QDateTime::currentDateTime(), QDateTime::fromString(), QDateTime::fromTime_t(), QDateTime::setDate(), QDateTime::setTime(), or QDateTime::setMSecsSinceEpoch() directly unless you follow it with a QDateTime::toUTC() or QDateTime::setDateSpec((Qt::UTC) depending on which method you use. You can use the QDateTime(QDate,QTime,Qt::TimeSpec) constructor, but only if you specify the Qt::TimeSpec. To make time manipulation in UTC easier given these constraints several utility function have been to the MythDate namespace (currently these live in libmythbase/util.{h,cpp}. QDateTime as_utc(const QDateTime&) -- Returns a copy of the QDateTime with the TimeSpec set to Qt::UTC, this can be used when pulling DATETIME values from the database. For Example, QDateTime tm = as_utc(query.value(0).toDateTime()); QDateTime current(bool stripped=false) -- Returns the current date and time in UTC. If stripped is set to true the millisecond portion of the time is stripped. QString current_iso_string(bool stripped=false) -- Returns current(stripped).toString(Qt::ISODate). Purely for convenience. QDateTime fromTime_t(uint s) -- Returns a QDateTime in UTC initialized from a time_t. QDateTime fromString(const QString&) -- Returns a QDateTime in UTC initialized from a string in either Qt::ISODate format or "yyyyMMddhhmmss" format. QDateTime fromString(const QString &date, const QString &format) -- Returns a QDateTime in UTC initialized using an arbitrary format, such as RFC822. QString toString(const QDateTime &, uint format) -- Returns a formatted string in one of the MythTV recognized formats. The format should be one or more of the flags in MythDate::Format. These come in two flavors, formats intended for use in the database or filesystem such as kISODate, kFilename, kDatabase default to UTC, while formats intended for display default to local time. You can override these defaults with the kOverrideUTC and kOverrideLocal flags. Traditionally MythTV has not set the timespec to Qt::UTC when dealing with UTC time, this presents problems when comparing times in local time to times in UTC. With the internal represetation of time in UTC it is important to either use these functions for initializing a QDateTime or to properly set the timespec otherwise time comparisons with times from Qt such as that returned from QFileInto::lastModified() will not work correction. As a corrilary, time represented in UTC with the timespec set correctly will compare correctly with a QDateTime in localtime with the timespec set correctly. So if you use these functions when initializing times represented in UTC you won't have any headaches dealing with the times returned from Qt functions. Since Qt returns times in localtime from it's various functions you will need to convert these to UTC when saving them in a variable for later use. This is accomplished with the toUTC() function. For example, QDateTime mod_time = QFileInfo("x.mpg").toUTC(); This is mainly so that people reading your code can safely assume all times are in UTC which saves them from having to figure out from the code whether you are using localtime or UTC. Another reason for doing this is in case the the variable is saved to the database, we want all times in the database to be in UTC for consistency.
- Loading branch information
1 parent
dd67c15
commit df47df3
Showing
146 changed files
with
1,342 additions
and
1,273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.