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

QDateTime at beginning of DST is created wrongly with recent glibc

    XMLWordPrintable

Details

    • Linux/Wayland
    • 21
    • 3d785249ba43cf4bd895ed679bac2791e0130dc5 (qt/qtbase/dev) b8f9c649dfb503a09dc3bc5714701bd059994cf5 (qt/qtbase/6.0) 91695b584ebaec6bac44bf52a4eab44da47d5a59 (qt/tqtc-qtbase/tqtc/lts-5.15)
    • Qt6_Foundation_Sprint 23, Qt6_Foundation_Sprint 24

    Description

      On Ubuntu20, QDateTimeEdit unit tests fail with errors like

      FAIL! : tst_QDateTimeEdit::stepIntoDSTGap(hour down into 02:00 gap) Compared values are not the same
       Actual (edit.dateTime()): 2007/03/25 00:00:10.000[CET]
       Expected (end) : 2007/03/25 01:00:10.000[CET]
       Loc: [../tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp(4747)]

      A simpler reproducer is attached.

      A patch which adds a unit test reproducing the problem in a simpler form in QDateTime (without QDateTimeEdit) is in Gerrit .

      Observation:

      When creating a QDateTime at e.g. 2007-03-25 02:00:00 (just at the beginning of the gap hour), we end up with a QDateTime at 2007-03-25 01:00:00 (one hour before the gap hour).

      Analysis:

      Creating the QDateTime at the beginning of the gap hour (I used 2007-03-25 02:00:00) creates a QDateTime with unknown DST status. It correctly calculates its local milliseconds since Epoch in winter time. Then in
      QDateTimePrivate::create
      is a call to
      refreshZonedDateTime (qdatetime.cpp:2793).
      This calls (qdatetime.cpp:2813)

      epochMSecs = localMSecsToEpochMSecs(msecs, &dstStatus, &testDate, &testTime);

      which correctly identifies the time to be (2007-03-25 03:00:00 DST). Here the problem arises. The DST information of the QDateTime object in question is updated from the result of localMSecsToEpochMSecs in (qdatetime.cpp:2814)

      status = mergeDaylightStatus(status, dstStatus);

      but the date/time information (given correctly in testDate/testTime) is not updated. So we end up with an object thinking it is 2007-03-25 02:00:00 DST, which is 2007-03-25 01:00:00. This is not what was asked for.

      Attachments

        1. main.cpp
          0.4 kB
        2. main2.cpp
          1 kB
        3. main3.cpp
          2 kB

        Issue Links

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

          Activity

            People

              andreasbuhr Andreas Buhr
              andreasbuhr Andreas Buhr
              Maurice Kalinowski Maurice Kalinowski
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes