Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. JavaScript Date => QDateTime problems for dates prior to 1981
Forum Updated to NodeBB v4.3 + New Features

JavaScript Date => QDateTime problems for dates prior to 1981

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    njeisecke
    wrote on last edited by
    #1

    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();
    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • N Offline
        N Offline
        njeisecke
        wrote on last edited by
        #3

        Done.

        For the record: https://bugreports.qt.nokia.com/browse/QTBUG-22582

        Nils

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved