Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-39734

QDateTime::offsetFromUtc() is zero when timeSpec() is Qt::TimeZone

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3: Somewhat important
    • None
    • 5.3.0
    • Core: Date/Time
    • 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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            johnlayt John Layt
            eugene128 Eugene Malashkin
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes