JavaScript Date => QDateTime problems for dates prior to 1981



  • The following code will display a wrong date for d1.

    The output of the following example is like this:

    Fri Apr 04 1980 00:00:00 GMT+0200 (CEST) => 03.04.80
    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):

    "Fr. Apr 4 00:00:00 1980"
    "Sa. Apr 4 00:00:00 1981"

    Could that considered to be a bug?

    Thanks!

    Qml example
    @
    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.toString() + " => " + Qt.formatDate(d1) + "<br>" + d2.toString() + " => " + Qt.formatDate(d2) + "<p>"
    }
    }
    @

    C++ example
    @
    #include <QtCore/QCoreApplication>
    #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.toString();
    qDebug() << d2.toString();
    }
    @



  • Hi,

    This certainly looks like a bug to me at first glance -- I'd suggest adding a bug via http://bugreports.qt.nokia.com .

    Regards,
    Michael




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.