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

QDateTime: weird side effects at DST shift time

    XMLWordPrintable

Details

    Description

      This test program:

      #include <QDateTime>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
      	QDateTime time1(QDate(2011, 10, 30), QTime(1, 0));
      
      	QDateTime time2 = time1.addSecs(3600 * 2);
      	QDateTime time3(QDate(2011, 10, 30), QTime(2, 0));
      
      	qDebug() << "time2:" << time2 << " msecs:" << time2.toMSecsSinceEpoch();
      	qDebug() << "time3:" << time3 << " msecs:" << time3.toMSecsSinceEpoch();
      
      	time2 = time1.addSecs(3600);
      
      	qDebug() << "time2:" << time2 << " msecs:" << time2.toMSecsSinceEpoch();
      	qDebug() << "time3:" << time3 << " msecs:" << time3.toMSecsSinceEpoch();
      
      	return 0;
      }
      

      produces the following output:

      time2: QDateTime("Sun Oct 30 02:00:00 2011")  msecs: 1319936400000 
      time3: QDateTime("Sun Oct 30 02:00:00 2011")  msecs: 1319936400000 
      time2: QDateTime("Sun Oct 30 02:00:00 2011")  msecs: 1319932800000 
      time3: QDateTime("Sun Oct 30 02:00:00 2011")  msecs: 1319932800000 
      

      After setting the value of time2 the output for time3 changes as well.

      My location is Berlin, Germany. On 2011-10-30 the time was shifted back from DST to standard time (CEST -> CET). The hour between 02:00 and 03:00 was thus repeated.

      Attachments

        For Gerrit Dashboard: QTBUG-22693
        # Subject Branch Project Status CR V

        Activity

          People

            johnlayt John Layt
            bonefish Ingo Weinhold
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes