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

JavaScript Date => QDateTime conversion problems for dates prior to 1981

    XMLWordPrintable

Details

    Description

      The following code will display a wrong date for d1.

      The output of the following example is like this:

      d1: Fri Apr 04 1980 00:00:00 GMT+0200 (CEST) => 03.04.80
      d2: Sat Apr 04 1981 00:00:00 GMT+0200 (CEST) => 04.04.81
      

      So in 1980 it's one day off.

      I guess there seems to be a problem with dst handling for dates prior to 1981.

      I suspect the problem has something to do with conversion from JS Date to QDateTime because basically the same thing works when used from the C++ side (see second code snippet):

      d1 "Fr. Apr 4 00:00:00 1980" 
      d2 "Sa. Apr 4 00:00:00 1981"
      
      date.qml
      import QtQuick 1.0
       
      Rectangle {
        width: 400; height: 360
       
        property date d1: new Date(1980, 3, 4, 0, 0, 0)
        property date d2: new Date(1981, 3, 4, 0, 0, 0)
       
        Text {
          anchors.centerIn: parent
          text: "<p>d1: " + d1.toString() + " => " + Qt.formatDate(d1) +  "<br>d2: " + d2.toString() + " => " + Qt.formatDate(d2) + "<p>"
        }
      }
      
      date.cpp
      #include <QDebug>
      #include <QDateTime>
       
      int main(int argc, char *argv[])
      {
        QDateTime d1(QDate(1980, 4, 4), QTime(0, 0, 0));
        QDateTime d2(QDate(1981, 4, 4), QTime(0, 0, 0));
       
        qDebug() << "d1" << d1.toString();
        qDebug() << "d2" << d2.toString();
      }
      

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            njeisecke Nils Jeisecke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes