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

QSqlite and QDateTime: QDateTime returned by query has is Qt::LocalTime timeSpec instead of Qt::UTC

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.7.4
    • SQL Support
    • None

    Description

      A date time is stored in SQLite as UTC.
      However, when I retrieve the date time via a query, the resulting QDateTime object uses the UTC time as local time, resulting in an offset when compared to a local time.

      QSqlQuery query("SELECT datetime('now')");
      QVERIFY(query.next());
      QDateTime dtdb = query.value(0).toDateTime(); // UTC time
      QCOMPARE(dtdb.timeSpec(), Qt::LocalTime); // this should be UTC, or read as a UTC time
      QDateTime dtqt = QDateTime::currentDateTime(); // local time
      int offset = dtdb.toTime_t() - dtqt.toTime_t(); // this should be very close zero, however this value is the same as the UTC offset to the local time (in seconds)

      Attachments

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

        Activity

          People

            mabrand Mark Brand
            ceumern delete me please
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes