From 15da0a5af20fe6771bcb94ef8d46edbd5c8fb64c Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 24 Apr 2013 13:38:13 +0200 Subject: Make QTime::toString output milliseconds for Qt::TextDate, Qt::ISODate. Section 4.2.2.4 of ISO 8601 allows for decimal fraction representations of dates and times. Currently, when calling QDateTime::toString(Qt::TextDate) or QDateTime::toString(Qt::ISODate), the milliseconds will be omitted. However, QDateTime::fromString(str, Qt::TextDate) and QDateTime::fromString(str, Qt::ISODate) already support decimal fraction representations, so this patch just adds this support to QTime::toString, and hence QDateTime::toString(). Task-number: QTBUG-30250 Change-Id: If58e4b3d3105322c51d11a76b832e5e634d8991f Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qtime/tst_qtime.cpp | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'tests/auto/corelib/tools/qtime') diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp index 97645ea7f6..95aed05e7c 100644 --- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp @@ -614,25 +614,27 @@ void tst_QTime::fromStringDateFormat() void tst_QTime::toStringDateFormat_data() { - // Since we can't define an element of Qt::DateFormat, str1 will be the string - // in TextDate format, and str2 will be the time in ISODate format. - - QTest::addColumn("t"); - QTest::addColumn("str1"); - QTest::addColumn("str2"); - - QTest::newRow( "data0" ) << QTime(0,0,0,0) << QString("00:00:00") << QString("00:00:00"); - QTest::newRow( "data1" ) << QTime(10,12,34,0) << QString("10:12:34") << QString("10:12:34"); + QTest::addColumn("time"); + QTest::addColumn("format"); + QTest::addColumn("expected"); + + QTest::newRow("00:00:00.000") << QTime(0, 0, 0, 0) << Qt::TextDate << QString("00:00:00.000"); + QTest::newRow("ISO 00:00:00.000") << QTime(0, 0, 0, 0) << Qt::ISODate << QString("00:00:00.000"); + QTest::newRow("Text 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::TextDate << QString("10:12:34.000"); + QTest::newRow("ISO 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::ISODate << QString("10:12:34.000"); + QTest::newRow("Text 10:12:34.001") << QTime(10, 12, 34, 001) << Qt::TextDate << QString("10:12:34.001"); + QTest::newRow("ISO 10:12:34.001") << QTime(10, 12, 34, 001) << Qt::ISODate << QString("10:12:34.001"); + QTest::newRow("Text 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::TextDate << QString("10:12:34.999"); + QTest::newRow("ISO 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::ISODate << QString("10:12:34.999"); } void tst_QTime::toStringDateFormat() { - QFETCH( QTime, t ); - QFETCH( QString, str1 ); - QFETCH( QString, str2 ); + QFETCH(QTime, time); + QFETCH(Qt::DateFormat, format); + QFETCH(QString, expected); - QCOMPARE( str1, t.toString( Qt::TextDate ) ); - QCOMPARE( str2, t.toString( Qt::ISODate ) ); + QCOMPARE(time.toString(format), expected); } void tst_QTime::toStringFormat_data() -- cgit v1.2.3