diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2016-11-03 19:00:24 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-11-14 17:18:21 +0000 |
commit | 948e24cb6deeaf0e55794032b90fdf20b7ef12c1 (patch) | |
tree | c611584badb1007adfa7b7dddb79264dab2cad8c /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | |
parent | 2b8b7a162be52f8cd6c2bc39f498a1ddfb59dd68 (diff) |
V4 Date.ParseString(): fix UTC-ness of date-only formats
ECMA-262 stipulates that date-only formats should be treated as UTC,
while date-times are handled as standard time, if no time zone is
explicitly given. Tidied up the parser a bit in the process and
documented what the spec says. Fixed some broken test-cases.
Handling of date-times without zone as local time is a correction
since edition 5.1 of ECMA-262 (which said to handle it as UTC):
http://www.ecma-international.org/ecma-262/7.0/index.html#sec-corrections-and-clarifications-in-ecmascript-2015-with-possible-compatibility-impact
We were previously handling both dates and date-times as local time,
violating the old spec for both and the revised spec for dates.
Task-number: QTBUG-56787
Change-Id: I557789d855b910ca6a859fca396af1a0205c9417
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 35f1534478..19c12ead1c 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -443,29 +443,37 @@ void tst_qqmlecmascript::assignBasicTypes() void tst_qqmlecmascript::assignDate_data() { QTest::addColumn<QUrl>("source"); + QTest::addColumn<int>("timeOffset"); // -1 for local-time, else minutes from UTC - 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"); - QTest::newRow("Binding UTC+2") << testFileUrl("assignDate.5.qml"); - QTest::newRow("Binding JS UTC+2 ") << testFileUrl("assignDate.6.qml"); + QTest::newRow("Component.onComplete JS Parse") << testFileUrl("assignDate.qml") << -1; + QTest::newRow("Component.onComplete JS") << testFileUrl("assignDate.1.qml") << 0; + QTest::newRow("Binding JS") << testFileUrl("assignDate.2.qml") << -1; + QTest::newRow("Binding UTC") << testFileUrl("assignDate.3.qml") << 0; + QTest::newRow("Binding JS UTC") << testFileUrl("assignDate.4.qml") << 0; + QTest::newRow("Binding UTC+2") << testFileUrl("assignDate.5.qml") << 120; + QTest::newRow("Binding JS UTC+2 ") << testFileUrl("assignDate.6.qml") << 120; } void tst_qqmlecmascript::assignDate() { QFETCH(QUrl, source); + QFETCH(int, timeOffset); QQmlComponent component(&engine, source); QScopedPointer<QObject> obj(component.create()); MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data()); QVERIFY(object != 0); - // 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()); + QDate expectedDate(2009, 5, 12); + QDateTime expectedDateTime; + QDateTime expectedDateTime2; + if (timeOffset == -1) { + expectedDateTime = QDateTime(QDate(2009, 5, 12), QTime(0, 0, 1), Qt::LocalTime); + expectedDateTime2 = QDateTime(QDate(2009, 5, 12), QTime(23, 59, 59), Qt::LocalTime); + } else { + expectedDateTime = QDateTime(QDate(2009, 5, 12), QTime(0, 0, 1), Qt::OffsetFromUTC, timeOffset * 60); + expectedDateTime2 = QDateTime(QDate(2009, 5, 12), QTime(23, 59, 59), Qt::OffsetFromUTC, timeOffset * 60); + } QCOMPARE(object->dateProperty(), expectedDate); QCOMPARE(object->dateTimeProperty(), expectedDateTime); |