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

Support Qt::OffsetFromUTC in QDateTime

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P4: Low
    • 5.2.0
    • 4.8.3
    • Core: Date/Time
    • None
    • openSUSE Linux 12.2 with custom built Qt 4.8.3 i586

    Description

      Look at this example:

      #include <QCoreApplication>
      #include <QDateTime>
      #include <QDebug>
      
      int main(int argc, char * argv[])
      {
          QDateTime dt;
          dt = QDateTime::fromString("2013-01-01T12:00:00-0600", Qt::ISODate);
          qDebug() << dt << dt.toUTC() << dt.toLocalTime() << dt.toUTC().toLocalTime();
          dt = QDateTime::fromString("2013-01-01T12:00:00-0400", Qt::ISODate);
          qDebug() << dt << dt.toUTC() << dt.toLocalTime() << dt.toUTC().toLocalTime();
          return 0;
      }
      

      This will output (in timezone UTC+1 and C locale):

      QDateTime("Tue Jan 1 12:00:00 2013") QDateTime("Tue Jan 1 18:00:00 2013") QDateTime("Tue Jan 1 12:00:00 2013") QDateTime("Tue Jan 1 19:00:00 2013") 
      QDateTime("Tue Jan 1 12:00:00 2013") QDateTime("Tue Jan 1 16:00:00 2013") QDateTime("Tue Jan 1 12:00:00 2013") QDateTime("Tue Jan 1 17:00:00 2013") 
      

      Notice how the third column (result of toLocalTime()) always returns the original hour values irrespective of the original timezone while the fourth column (result of toUTC().toLocalTime()) actually shows the correct local time.

      I think, at least QDateTime::toTimeSpec() and QDateTimePrivate::getLocal() need to be fixed.

      Attachments

        Issue Links

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

          Activity

            People

              johnlayt John Layt
              tvogel Tilman Vogel
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes