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

windows specific: QDateTime provides wrong value for toUTC in DST

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: P3: Somewhat important P3: Somewhat important
    • Some future release
    • 4.6.0
    • Core: Date/Time
    • None
    • Windows XP, qt-4.6.0, vs2005

      It happens when you set the time on Windows within the magic hour Oct.31 2010 02:00 to 02:59:59
      It seems that Windows consider this time to be summer hour, but Qt calculates as if it is winter hour, so the time value we get from Qt is one hour ahead than the real system time.
      And the time_t is one hour ahead to the real time_t, so when it reaches 03:00, the time_t value will jump over the -3600 gap to the correct value.

      Test code for Qt:

      	uint time1 = QDateTime::currentDateTime().toUTC().toTime_t();
      	uint time2 = QDateTime::currentDateTime().toTime_t();
      	qWarning("UTC(%d), (%d)", time1, time2);
      	qWarning() << QDateTime::currentDateTime().toUTC();
      	qWarning() << QDateTime::currentDateTime();
      

      Test code for Windows:

          SYSTEMTIME st, lt;
          GetSystemTime(&st);
          GetLocalTime(&lt);
       
      	time_t ltime;
      	time(&ltime);   
          qWarning("The system time is: %02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
          qWarning("The local time is: %02d:%02d:%02d", lt.wHour, lt.wMinute, lt.wSecond);
          qWarning("time_t: %ld", ltime);
      

      Sample output:

      UTC(1288490399), (1288490399)
      QDateTime("Sun Oct 31 01:59:59 2010")
      QDateTime("Sun Oct 31 02:59:59 2010")
      UTC(1288486800), (1288486800)
      QDateTime("Sun Oct 31 01:00:00 2010")
      QDateTime("Sun Oct 31 02:00:00 2010")
      ---------------------------------------------------------
      The system time is: 00:59:59
      The local time is: 02:59:59
      time_t: 1288486799
      The system time is: 01:00:00
      The local time is: 02:00:00
      time_t: 1288486800
      

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

            johnlayt John Layt
            sanonymous Nokia Qt Support (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes