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

Qml date behaves unexpectedly for negative years

    XMLWordPrintable

Details

    Description

      Running the following QML gives unexpected results:

      import QtQuick 2.0
      Item {
          width: 360
          height: 360
      
          property date date1: new Date()
          property date date2: new Date()
      
          Component.onCompleted: {
              console.log("date1 initial value: " + date1)
              var tmpDate = date1
              console.log("tmpDate initial value: " + tmpDate
              date1.setUTCFullYear(-1000)
              console.log("date1 -1000 year value: " + date1 + " (unexpected result!)")
              tmpDate.setUTCFullYear(-1000)
              console.log("tmpDate -1000 year value: " + tmpDate)
              date1 = tmpDate
              date2 = tmpDate
              console.log("date1 = tmpDate, date2 = tmpDate:")
              console.log("date1: " + date1 + " (unexpected year change, should be -1000!)")
              console.log("date2: " + date2 + " (unexpected year change, should be -1000!)")
              date2 = date1
              console.log("date2 = date1:")
              console.log("date1: " + date1)
              console.log("date2: " + date2 + " (notice the year increase!)")
              console.log("date1 == date2: " + (date1 == date2) + " (unexpected!)")
              date1 = date2
              console.log("date1 = date2:")
              console.log("date1: " + date1 + " (notice the year increase!)")
              console.log("date2: " + date2)
              console.log("date1 == date2: " + (date1 == date2) + " (unexpected!)")
          }
      }
      

      Output:
      Starting /home/acracan/Qt5.2.1/5.2.1/gcc_64/bin/qmlscene...
      date1 initial value: Mi feb. 12 13:24:00 2014 GMT+0200
      tmpDate initial value: Mi feb. 12 13:24:00 2014 GMT+0200
      date1 -1000 year value: Mi feb. 12 13:24:00 2014 GMT+0200 (unexpected result!)
      tmpDate -1000 year value: Jo feb. 12 11:24:00 -1000 GMT+0200
      date1 = tmpDate, date2 = tmpDate:
      date1: Vi feb. 12 11:24:00 -999 GMT+0200 (unexpected year change, should be -1000!)
      date2: Vi feb. 12 11:24:00 -999 GMT+0200 (unexpected year change, should be -1000!)
      date2 = date1:
      date1: Vi feb. 12 11:24:00 -999 GMT+0200
      date2: Sâ feb. 12 11:24:00 -998 GMT+0200 (notice the year increase!)
      date1 == date2: false (unexpected!)
      date1 = date2:
      date1: Du feb. 12 11:24:00 -997 GMT+0200 (notice the year increase!)
      date2: Sâ feb. 12 11:24:00 -998 GMT+0200
      date1 == date2: false (unexpected!)
      /home/acracan/Qt5.2.1/5.2.1/gcc_64/bin/qmlscene exited with code 0

      Attachments

        1. test_date.qml
          1 kB
          Arcadie Cracan

        Issue Links

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

          Activity

            People

              vkotov Valery Kotov
              acracan Arcadie Cracan
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes