diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2014-12-11 14:05:31 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2014-12-12 12:56:57 +0100 |
commit | 68c2c56a1a3d7948c687ffae3a9d3c6cbd06a527 (patch) | |
tree | a577ad94d46e625512351b2d0a67d76c91e90004 /tests/auto/qml/qqmlecmascript | |
parent | 6179550a0ca761bfabd4f6c67103f5397a306df0 (diff) |
Revert "Properly handle negative years when printing JS Dates to strings."
This reverts commit f06daaf3d8747c6c0a277bf055c80d8f2e7bcc81.
The only things actually specified by the ECMAScript standard on dates
are:
1. Reparsing a date output from any of the to*String() functions has to
result in the same date representation.
2. The ISO 8601 standard has to be followed for the ISO format.
Currently we clearly don't follow rule 1. Date.parse(d.toString()) will
not yield the same as d.valueOf() for negative dates.
The ISO 8601 standard clearly has a year 0 while common human language
has not. All non ISO date representations are considered
"implementation-dependent" in the ECMAScript standard. We can thus
define the relation between our representations and the ISO standard any
way we like. If we try to match up the dates so that the negative years
look equal in each representation we cannot properly interact with QDate
for dates in the year 0 as that doesn't exist in QDate. We can, however,
choose not to make the dates look equal. That means a date with a
negative year will be "one off" when represented in ISO 8601. "333 BC"
in human language is "-332" in ISO 8601. Our internal representation is
aligned to ISO 8601 and the to*String() methods may output something
else. That means we can easily set the year in ISO 8601 sense from the
Date constructor as well as from setYear() and setFullYear().
This, of course, is somewhat unintuitive and also differs from most
other JavaScript implementations (which don't have to interoperate with
QDate). However, it is still correct.
Change-Id: I5fc26b709a486cb520a075918b184a80bec56c9b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/negativeyear.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 8 |
2 files changed, 11 insertions, 4 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/negativeyear.qml b/tests/auto/qml/qqmlecmascript/data/negativeyear.qml index 11defbe914..e6c857d266 100644 --- a/tests/auto/qml/qqmlecmascript/data/negativeyear.qml +++ b/tests/auto/qml/qqmlecmascript/data/negativeyear.qml @@ -2,7 +2,12 @@ import QtQuick 2.0 import Qt.test 1.0 Item { - function check_negative() { + function check_negative_tostring() { return "result: " + new Date(-2000, 0, 1); } + + function check_negative_toisostring() { + // Make that february, to avoid timezone problems + return "result: " + (new Date(-2000, 1, 1)).toISOString(); + } } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 07f59eb488..c05ac7a052 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -7387,10 +7387,12 @@ void tst_qqmlecmascript::negativeYear() QVERIFY(object != 0); QVariant q; - QMetaObject::invokeMethod(object, "check_negative", - Q_RETURN_ARG(QVariant, q)); + QMetaObject::invokeMethod(object, "check_negative_tostring", Q_RETURN_ARG(QVariant, q)); // Strip the timezone. It should be irrelevant as the date was created with the same one. - QCOMPARE(q.toString().left(32), QStringLiteral("result: Mon Jan 1 00:00:00 -2000")); + QCOMPARE(q.toString().left(32), QStringLiteral("result: Sat Jan 1 00:00:00 -2001")); + + QMetaObject::invokeMethod(object, "check_negative_toisostring", Q_RETURN_ARG(QVariant, q)); + QCOMPARE(q.toString().left(16), QStringLiteral("result: -002000-")); } void tst_qqmlecmascript::concatenatedStringPropertyAccess() |