Record current status of date conversion from QML
authorMatthew Vogt <matthew.vogt@nokia.com>
Fri, 13 Apr 2012 06:12:55 +0000 (16:12 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 23 Apr 2012 22:33:00 +0000 (00:33 +0200)
Ensure that the qqmlecmascript test is not broken by changes in the
time zone of the test environment.

This test documents the existing situation with convertibility
of date information between QML and JS.

Task-number: QTBUG-25262
Change-Id: I42716e0b34ef26daa391fdb4aebc1f31340fcea0
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
tests/auto/qml/qqmlecmascript/data/assignDate.1.qml [new file with mode: 0644]
tests/auto/qml/qqmlecmascript/data/assignDate.2.qml
tests/auto/qml/qqmlecmascript/data/assignDate.3.qml
tests/auto/qml/qqmlecmascript/data/assignDate.4.qml
tests/auto/qml/qqmlecmascript/data/assignDate.5.qml
tests/auto/qml/qqmlecmascript/data/assignDate.6.qml
tests/auto/qml/qqmlecmascript/data/assignDate.qml
tests/auto/qml/qqmlecmascript/testtypes.h
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.1.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.1.qml
new file mode 100644 (file)
index 0000000..efca6cd
--- /dev/null
@@ -0,0 +1,35 @@
+import Qt.test 1.0
+import QtQuick 2.0
+
+MyTypeObject {
+    Component.onCompleted: {
+        var dateVar = new Date(Date.UTC(2009, 4, 12))
+        var dateTimeVar = new Date(Date.UTC(2009, 4, 12, 0, 0, 1))
+        var dateTimeVar2 = new Date(Date.UTC(2009, 4, 12, 23, 59, 59))
+
+        dateProperty = dateVar
+        dateTimeProperty = dateTimeVar
+        dateTimeProperty2 = dateTimeVar2
+
+        // Commented properties do not currently test true:
+        boolProperty = //(dateProperty.getTime() == dateVar.getTime()) &&
+                       (dateProperty.getFullYear() == 2009) &&
+                       (dateProperty.getMonth() == 5-1) &&
+                       //(dateProperty.getDate() == 12) &&
+                       (dateProperty.getHours() == 0) &&
+                       (dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
+                       (dateTimeProperty.getFullYear() == 2009) &&
+                       (dateTimeProperty.getMonth() == 5-1) &&
+                       //(dateTimeProperty.getDate() == 12) &&
+                       //(dateTimeProperty.getHours() == 0) &&
+                       (dateTimeProperty.getMinutes() == 0) &&
+                       (dateTimeProperty.getSeconds() == 1) &&
+                       (dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
+                       (dateTimeProperty2.getFullYear() == 2009) &&
+                       (dateTimeProperty2.getMonth() == 5-1) &&
+                       //(dateTimeProperty2.getDate() == 12) &&
+                       //(dateTimeProperty2.getHours() == 23) &&
+                       (dateTimeProperty2.getMinutes() == 59) &&
+                       (dateTimeProperty2.getSeconds() == 59)
+    }
+}
index 5787018..71dd188 100644 (file)
@@ -1,6 +1,36 @@
 import Qt.test 1.0
+import QtQuick 2.0
 
 MyTypeObject {
-    dateProperty: if(1) new Date("1982-11-25")
-    dateTimeProperty: if(1) new Date("2009-05-12T13:22:01")
+    dateProperty: if (1) new Date("2009-05-12")
+    dateTimeProperty: if (1) new Date("2009-05-12T00:00:01")
+    dateTimeProperty2: if (1) new Date("2009-05-12T23:59:59")
+
+    boolProperty: false
+    Component.onCompleted: {
+        var dateVar = new Date("2009-05-12")
+        var dateTimeVar = new Date("2009-05-12T00:00:01")
+        var dateTimeVar2 = new Date("2009-05-12T23:59:59")
+
+        // Commented properties do not currently test true:
+        boolProperty = //(dateProperty.getTime() == dateVar.getTime()) &&
+                       (dateProperty.getFullYear() == 2009) &&
+                       (dateProperty.getMonth() == 5-1) &&
+                       //(dateProperty.getDate() == 12) &&
+                       (dateProperty.getHours() == 0) &&
+                       (dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
+                       (dateTimeProperty.getFullYear() == 2009) &&
+                       (dateTimeProperty.getMonth() == 5-1) &&
+                       //(dateTimeProperty.getDate() == 12) &&
+                       //(dateTimeProperty.getHours() == 0) &&
+                       (dateTimeProperty.getMinutes() == 0) &&
+                       (dateTimeProperty.getSeconds() == 1) &&
+                       (dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
+                       (dateTimeProperty2.getFullYear() == 2009) &&
+                       (dateTimeProperty2.getMonth() == 5-1) &&
+                       //(dateTimeProperty2.getDate() == 12) &&
+                       //(dateTimeProperty2.getHours() == 23) &&
+                       (dateTimeProperty2.getMinutes() == 59) &&
+                       (dateTimeProperty2.getSeconds() == 59)
+    }
 }
index 32b88d0..2cf7406 100644 (file)
@@ -1,6 +1,36 @@
 import Qt.test 1.0
+import QtQuick 2.0
 
 MyTypeObject {
-    dateProperty: if(1) "1982-11-25Z"
-    dateTimeProperty: if(1) "2009-05-12T13:22:01Z"
+    dateProperty: if (1) "2009-05-12Z"
+    dateTimeProperty: if (1) "2009-05-12T00:00:01Z"
+    dateTimeProperty2: if (1) "2009-05-12T23:59:59Z"
+
+    boolProperty: false
+    Component.onCompleted: {
+        var dateVar = new Date("2009-05-12Z")
+        var dateTimeVar = new Date("2009-05-12T00:00:01Z")
+        var dateTimeVar2 = new Date("2009-05-12T23:59:59Z")
+
+        // Commented properties do not currently test true:
+        boolProperty = //(dateProperty.getTime() == dateVar.getTime()) &&
+                       (dateProperty.getFullYear() == 2009) &&
+                       (dateProperty.getMonth() == 5-1) &&
+                       //(dateProperty.getDate() == 12) &&
+                       (dateProperty.getHours() == 0) &&
+                       (dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
+                       (dateTimeProperty.getFullYear() == 2009) &&
+                       (dateTimeProperty.getMonth() == 5-1) &&
+                       //(dateTimeProperty.getDate() == 12) &&
+                       //(dateTimeProperty.getHours() == 0) &&
+                       (dateTimeProperty.getMinutes() == 0) &&
+                       (dateTimeProperty.getSeconds() == 1) &&
+                       (dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
+                       (dateTimeProperty2.getFullYear() == 2009) &&
+                       (dateTimeProperty2.getMonth() == 5-1) &&
+                       //(dateTimeProperty2.getDate() == 12) &&
+                       //(dateTimeProperty2.getHours() == 23) &&
+                       (dateTimeProperty2.getMinutes() == 59) &&
+                       (dateTimeProperty2.getSeconds() == 59)
+    }
 }
index 16213c6..9b4975c 100644 (file)
@@ -1,6 +1,36 @@
 import Qt.test 1.0
+import QtQuick 2.0
 
 MyTypeObject {
-    dateProperty: if(1) new Date("1982-11-25Z")
-    dateTimeProperty: if(1) new Date("2009-05-12T13:22:01Z")
+    dateProperty: if (1) new Date("2009-05-12Z")
+    dateTimeProperty: if (1) new Date("2009-05-12T00:00:01Z")
+    dateTimeProperty2: if (1) new Date("2009-05-12T23:59:59Z")
+
+    boolProperty: false
+    Component.onCompleted: {
+        var dateVar = new Date("2009-05-12Z")
+        var dateTimeVar = new Date("2009-05-12T00:00:01Z")
+        var dateTimeVar2 = new Date("2009-05-12T23:59:59Z")
+
+        // Commented properties do not currently test true:
+        boolProperty = //(dateProperty.getTime() == dateVar.getTime()) &&
+                       (dateProperty.getFullYear() == 2009) &&
+                       (dateProperty.getMonth() == 5-1) &&
+                       //(dateProperty.getDate() == 12) &&
+                       (dateProperty.getHours() == 0) &&
+                       (dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
+                       (dateTimeProperty.getFullYear() == 2009) &&
+                       (dateTimeProperty.getMonth() == 5-1) &&
+                       //(dateTimeProperty.getDate() == 12) &&
+                       //(dateTimeProperty.getHours() == 0) &&
+                       (dateTimeProperty.getMinutes() == 0) &&
+                       (dateTimeProperty.getSeconds() == 1) &&
+                       (dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
+                       (dateTimeProperty2.getFullYear() == 2009) &&
+                       (dateTimeProperty2.getMonth() == 5-1) &&
+                       //(dateTimeProperty2.getDate() == 12) &&
+                       //(dateTimeProperty2.getHours() == 23) &&
+                       (dateTimeProperty2.getMinutes() == 59) &&
+                       (dateTimeProperty2.getSeconds() == 59)
+    }
 }
index ff1d85f..2cf7406 100644 (file)
@@ -1,6 +1,36 @@
 import Qt.test 1.0
+import QtQuick 2.0
 
 MyTypeObject {
-    dateProperty: if(1) "1982-11-25Z"
-    dateTimeProperty: if(1) "2009-05-12T15:22:01+02:00"
+    dateProperty: if (1) "2009-05-12Z"
+    dateTimeProperty: if (1) "2009-05-12T00:00:01Z"
+    dateTimeProperty2: if (1) "2009-05-12T23:59:59Z"
+
+    boolProperty: false
+    Component.onCompleted: {
+        var dateVar = new Date("2009-05-12Z")
+        var dateTimeVar = new Date("2009-05-12T00:00:01Z")
+        var dateTimeVar2 = new Date("2009-05-12T23:59:59Z")
+
+        // Commented properties do not currently test true:
+        boolProperty = //(dateProperty.getTime() == dateVar.getTime()) &&
+                       (dateProperty.getFullYear() == 2009) &&
+                       (dateProperty.getMonth() == 5-1) &&
+                       //(dateProperty.getDate() == 12) &&
+                       (dateProperty.getHours() == 0) &&
+                       (dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
+                       (dateTimeProperty.getFullYear() == 2009) &&
+                       (dateTimeProperty.getMonth() == 5-1) &&
+                       //(dateTimeProperty.getDate() == 12) &&
+                       //(dateTimeProperty.getHours() == 0) &&
+                       (dateTimeProperty.getMinutes() == 0) &&
+                       (dateTimeProperty.getSeconds() == 1) &&
+                       (dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
+                       (dateTimeProperty2.getFullYear() == 2009) &&
+                       (dateTimeProperty2.getMonth() == 5-1) &&
+                       //(dateTimeProperty2.getDate() == 12) &&
+                       //(dateTimeProperty2.getHours() == 23) &&
+                       (dateTimeProperty2.getMinutes() == 59) &&
+                       (dateTimeProperty2.getSeconds() == 59)
+    }
 }
index 859c02f..73e26db 100644 (file)
@@ -1,6 +1,36 @@
 import Qt.test 1.0
+import QtQuick 2.0
 
 MyTypeObject {
-    dateProperty: if(1) new Date("1982-11-25")
-    dateTimeProperty: if(1) new Date("2009-05-12T15:22:01+02:00")
+    dateProperty: if (1) new Date("2009-05-12")
+    dateTimeProperty: if (1) new Date("2009-05-12T02:00:01+02:00")
+    dateTimeProperty2: if (1) new Date("2009-05-13T01:59:59+02:00")
+
+    boolProperty: false
+    Component.onCompleted: {
+        var dateVar = new Date("2009-05-12")
+        var dateTimeVar = new Date("2009-05-12T02:00:01+02:00")
+        var dateTimeVar2 = new Date("2009-05-13T01:59:59+02:00")
+
+        // Commented properties do not currently test true:
+        boolProperty = //(dateProperty.getTime() == dateVar.getTime()) &&
+                       (dateProperty.getFullYear() == 2009) &&
+                       (dateProperty.getMonth() == 5-1) &&
+                       //(dateProperty.getDate() == 12) &&
+                       (dateProperty.getHours() == 0) &&
+                       (dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
+                       (dateTimeProperty.getFullYear() == 2009) &&
+                       (dateTimeProperty.getMonth() == 5-1) &&
+                       //(dateTimeProperty.getDate() == 12) &&
+                       //(dateTimeProperty.getHours() == 0) &&
+                       (dateTimeProperty.getMinutes() == 0) &&
+                       (dateTimeProperty.getSeconds() == 1) &&
+                       (dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
+                       (dateTimeProperty2.getFullYear() == 2009) &&
+                       (dateTimeProperty2.getMonth() == 5-1) &&
+                       //(dateTimeProperty2.getDate() == 12) &&
+                       //(dateTimeProperty2.getHours() == 23) &&
+                       (dateTimeProperty2.getMinutes() == 59) &&
+                       (dateTimeProperty2.getSeconds() == 59)
+    }
 }
index 07a638d..14fe207 100644 (file)
@@ -3,7 +3,33 @@ import QtQuick 2.0
 
 MyTypeObject {
     Component.onCompleted: {
-        dateProperty = new Date("1982-11-25")
-        dateTimeProperty = new Date("2009-05-12T13:22:01")
+        var dateVar = new Date("2009-05-12")
+        var dateTimeVar = new Date("2009-05-12T00:00:01")
+        var dateTimeVar2 = new Date("2009-05-12T23:59:59")
+
+        dateProperty = dateVar
+        dateTimeProperty = dateTimeVar
+        dateTimeProperty2 = dateTimeVar2
+
+        // Commented properties do not currently test true:
+        boolProperty = //(dateProperty.getTime() == dateVar.getTime()) &&
+                       (dateProperty.getFullYear() == 2009) &&
+                       (dateProperty.getMonth() == 5-1) &&
+                       //(dateProperty.getDate() == 12) &&
+                       (dateProperty.getHours() == 0) &&
+                       (dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
+                       (dateTimeProperty.getFullYear() == 2009) &&
+                       (dateTimeProperty.getMonth() == 5-1) &&
+                       //(dateTimeProperty.getDate() == 12) &&
+                       //(dateTimeProperty.getHours() == 0) &&
+                       (dateTimeProperty.getMinutes() == 0) &&
+                       (dateTimeProperty.getSeconds() == 1) &&
+                       (dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
+                       (dateTimeProperty2.getFullYear() == 2009) &&
+                       (dateTimeProperty2.getMonth() == 5-1) &&
+                       //(dateTimeProperty2.getDate() == 12) &&
+                       //(dateTimeProperty2.getHours() == 23) &&
+                       (dateTimeProperty2.getMinutes() == 59) &&
+                       (dateTimeProperty2.getSeconds() == 59)
     }
 }
index 167e944..b0d7e0f 100644 (file)
@@ -360,6 +360,7 @@ class MyTypeObject : public QObject
     Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty)
     Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty)
     Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty)
+    Q_PROPERTY(QDateTime dateTimeProperty2 READ dateTimeProperty2 WRITE setDateTimeProperty2)
     Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty)
     Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty)
     Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty)
@@ -501,6 +502,14 @@ public:
         dateTimePropertyValue = v;
     }
 
+    QDateTime dateTimePropertyValue2;
+    QDateTime dateTimeProperty2() const {
+       return dateTimePropertyValue2;
+    }
+    void setDateTimeProperty2(const QDateTime &v) {
+        dateTimePropertyValue2 = v;
+    }
+
     QPoint pointPropertyValue;
     QPoint pointProperty() const {
        return pointPropertyValue;
index c2d490e..4e7da76 100644 (file)
@@ -332,7 +332,9 @@ void tst_qqmlecmascript::assignBasicTypes()
 void tst_qqmlecmascript::assignDate_data()
 {
     QTest::addColumn<QUrl>("source");
-    QTest::newRow("Component.onComplete JS") << testFileUrl("assignDate.qml");
+
+    QTest::newRow("Component.onComplete JS Parse") << testFileUrl("assignDate.qml");
+    QTest::newRow("Component.onComplete JS") << testFileUrl("assignDate.1.qml");
     QTest::newRow("Binding JS") << testFileUrl("assignDate.2.qml");
     QTest::newRow("Binding UTC") << testFileUrl("assignDate.3.qml");
     QTest::newRow("Binding JS UTC") << testFileUrl("assignDate.4.qml");
@@ -343,12 +345,21 @@ void tst_qqmlecmascript::assignDate_data()
 void tst_qqmlecmascript::assignDate()
 {
     QFETCH(QUrl, source);
+
     QQmlComponent component(&engine, source);
     QScopedPointer<QObject> obj(component.create());
     MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
     QVERIFY(object != 0);
-    QCOMPARE(object->dateProperty(), QDate(1982, 11, 25));
-    QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1), Qt::UTC));
+
+    // Dates received from JS are automatically converted to local time
+    QDate expectedDate(QDateTime(QDate(2009, 5, 12), QTime(0, 0, 0), Qt::UTC).toLocalTime().date());
+    QDateTime expectedDateTime(QDateTime(QDate(2009, 5, 12), QTime(0, 0, 1), Qt::UTC).toLocalTime());
+    QDateTime expectedDateTime2(QDateTime(QDate(2009, 5, 12), QTime(23, 59, 59), Qt::UTC).toLocalTime());
+
+    QCOMPARE(object->dateProperty(), expectedDate);
+    QCOMPARE(object->dateTimeProperty(), expectedDateTime);
+    QCOMPARE(object->dateTimeProperty2(), expectedDateTime2);
+    QCOMPARE(object->boolProperty(), true);
 }
 
 void tst_qqmlecmascript::idShortcutInvalidates()