From 421ee46b982d274fe7e7a2f7a4269e39134d31d2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 27 Sep 2013 14:48:07 -0700 Subject: Autotest: Fix unexpected rounding of floating point in date tests QString("new Date(%0)").arg(1380318500 * 1000.0) expands to "new Date(1.38032e+12)". That's an unnecessary rounding and cuts off interesting bits out of the date. It took me quite a while debugging QScriptEngine trying to find out why the time_t and the JS Date internal numbers were different. Change-Id: Id880f3f11edd0af07e1726eac0242d4a9625c368 Reviewed-by: John Layt --- tests/auto/qscriptengine/tst_qscriptengine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index c75f652..c9318c7 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -5812,7 +5812,7 @@ void tst_QScriptEngine::dateRoundtripJSQtJS() uint secs = QDateTime(QDate(2009, 1, 1)).toUTC().toTime_t(); QScriptEngine eng; for (int i = 0; i < 8000; ++i) { - QScriptValue jsDate = eng.evaluate(QString::fromLatin1("new Date(%0)").arg(secs * 1000.0)); + QScriptValue jsDate = eng.evaluate(QString::fromLatin1("new Date(%0 * 1000.0)").arg(secs)); QDateTime qtDate = jsDate.toDateTime(); QScriptValue jsDate2 = eng.newDate(qtDate); if (jsDate2.toNumber() != jsDate.toNumber()) @@ -5839,7 +5839,7 @@ void tst_QScriptEngine::dateConversionJSQt() uint secs = QDateTime(QDate(2009, 1, 1)).toUTC().toTime_t(); QScriptEngine eng; for (int i = 0; i < 8000; ++i) { - QScriptValue jsDate = eng.evaluate(QString::fromLatin1("new Date(%0)").arg(secs * 1000.0)); + QScriptValue jsDate = eng.evaluate(QString::fromLatin1("new Date(%0 * 1000.0)").arg(secs)); QDateTime qtDate = jsDate.toDateTime(); QString qtUTCDateStr = qtDate.toUTC().toString(Qt::ISODate); QString jsUTCDateStr = jsDate.property("toISOString").call(jsDate).toString(); -- cgit v1.2.1