aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlstringconverters.cpp3
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.2.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.3.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.4.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.5.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.6.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.qml9
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp28
8 files changed, 68 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlstringconverters.cpp b/src/qml/qml/qqmlstringconverters.cpp
index 2c7f6c9f6e..82f4f7db03 100644
--- a/src/qml/qml/qqmlstringconverters.cpp
+++ b/src/qml/qml/qqmlstringconverters.cpp
@@ -174,6 +174,9 @@ QDateTime QQmlStringConverters::dateTimeFromString(const QString &s, bool *ok)
{
QDateTime d = QDateTime::fromString(s, Qt::ISODate);
if (ok) *ok = d.isValid();
+ // V8 never parses a date string as local time. For consistency do the same here.
+ if (d.timeSpec() == Qt::LocalTime)
+ d.setTimeSpec(Qt::UTC);
return d;
}
#endif // QT_NO_DATESTRING
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.2.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.2.qml
new file mode 100644
index 0000000000..578701844c
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.2.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+MyTypeObject {
+ dateProperty: if(1) new Date("1982-11-25")
+ dateTimeProperty: if(1) new Date("2009-05-12T13:22:01")
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.3.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.3.qml
new file mode 100644
index 0000000000..32b88d0183
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.3.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+MyTypeObject {
+ dateProperty: if(1) "1982-11-25Z"
+ dateTimeProperty: if(1) "2009-05-12T13:22:01Z"
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.4.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.4.qml
new file mode 100644
index 0000000000..16213c691f
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.4.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+MyTypeObject {
+ dateProperty: if(1) new Date("1982-11-25Z")
+ dateTimeProperty: if(1) new Date("2009-05-12T13:22:01Z")
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.5.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.5.qml
new file mode 100644
index 0000000000..ff1d85fbef
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.5.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+MyTypeObject {
+ dateProperty: if(1) "1982-11-25Z"
+ dateTimeProperty: if(1) "2009-05-12T15:22:01+02:00"
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.6.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.6.qml
new file mode 100644
index 0000000000..859c02f79c
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.6.qml
@@ -0,0 +1,6 @@
+import Qt.test 1.0
+
+MyTypeObject {
+ dateProperty: if(1) new Date("1982-11-25")
+ dateTimeProperty: if(1) new Date("2009-05-12T15:22:01+02:00")
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.qml
new file mode 100644
index 0000000000..07a638d50f
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.qml
@@ -0,0 +1,9 @@
+import Qt.test 1.0
+import QtQuick 2.0
+
+MyTypeObject {
+ Component.onCompleted: {
+ dateProperty = new Date("1982-11-25")
+ dateTimeProperty = new Date("2009-05-12T13:22:01")
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 650197ea4f..ca4708e7ee 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -71,6 +71,8 @@ public:
private slots:
void initTestCase();
void assignBasicTypes();
+ void assignDate_data();
+ void assignDate();
void idShortcutInvalidates();
void boolPropertiesEvaluateAsBool();
void methods();
@@ -278,7 +280,7 @@ void tst_qqmlecmascript::assignBasicTypes()
QCOMPARE(object->colorProperty(), QColor("red"));
QCOMPARE(object->dateProperty(), QDate(1982, 11, 25));
QCOMPARE(object->timeProperty(), QTime(11, 11, 32));
- QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1)));
+ QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1), Qt::UTC));
QCOMPARE(object->pointProperty(), QPoint(99,13));
QCOMPARE(object->pointFProperty(), QPointF(-10.1, 12.3));
QCOMPARE(object->sizeProperty(), QSize(99, 13));
@@ -306,7 +308,7 @@ void tst_qqmlecmascript::assignBasicTypes()
QCOMPARE(object->colorProperty(), QColor("red"));
QCOMPARE(object->dateProperty(), QDate(1982, 11, 25));
QCOMPARE(object->timeProperty(), QTime(11, 11, 32));
- QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1)));
+ QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1), Qt::UTC));
QCOMPARE(object->pointProperty(), QPoint(99,13));
QCOMPARE(object->pointFProperty(), QPointF(-10.1, 12.3));
QCOMPARE(object->sizeProperty(), QSize(99, 13));
@@ -321,6 +323,28 @@ void tst_qqmlecmascript::assignBasicTypes()
}
}
+void tst_qqmlecmascript::assignDate_data()
+{
+ QTest::addColumn<QUrl>("source");
+ QTest::newRow("Component.onComplete JS") << testFileUrl("assignDate.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");
+ QTest::newRow("Binding UTC+2") << testFileUrl("assignDate.5.qml");
+ QTest::newRow("Binding JS UTC+2 ") << testFileUrl("assignDate.6.qml");
+}
+
+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));
+}
+
void tst_qqmlecmascript::idShortcutInvalidates()
{
{