Details
-
Bug
-
Resolution: Duplicate
-
P3: Somewhat important
-
None
-
5.3.0
-
None
-
Win7, MS VS2013
Description
Documentation on method int QDateTime::offsetFromUtc():
If the timeSpec() is Qt::TimeZone this will be the offset effective in the Time Zone including any Daylight Saving Offset
But when I create QDateTime object with appropriate QTimeZone, offsetFromUtc of this object is always zero:
#include <QCoreApplication> #include <QDateTime> #include <QTimeZone> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // Appropriate timezone QTimeZone systemTimeZone("Europe/Moscow"); // QDateTime object with appropriate timezone QDateTime dateTime(QDate(2014, 6, 18), QTime(17, 00), systemTimeZone); // Here is the bug: qDebug() << dateTime.offsetFromUtc(); // is 0, that's wrong! // but qDebug() << systemTimeZone.offsetFromUtc(dateTime); // is 14400, that's right return a.exec(); }
This cause incorrect conversion time from appropriate timezone to local, because toLocalTime() method uses offsertFromUtc.