From bcd19b723a4adad4d5f1dbbd35079cc24331dfa8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 30 Sep 2016 11:18:05 -0700 Subject: QLocale: fix handling of milliseconds in string format and document [ChangeLog][QtCore][QLocale] Fixed the conversion of QTime to string form and parsing from string form to always treat the value as the decimal fraction of the seconds component. That is, the string format ".z" produces/parses ".2" for 200 milliseconds and ".002" for 2 milliseconds. Use of "z" or "zzz" is discouraged outside decimal fractions to avoid surprises. Task-number: QTBUG-53565 Change-Id: Ia19de85ad35e4eb7bb95fffd14792caf9b4a5156 Reviewed-by: Edward Welbourne --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 19 +++++++++++-------- tests/auto/corelib/tools/qtime/tst_qtime.cpp | 15 +++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 9ca8766592..f278a7470b 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -1302,10 +1302,11 @@ void tst_QLocale::formatTime_data() QTest::newRow("28") << QTime(1, 2, 3, 456) << "H:m:s.z" << "1:2:3.456"; QTest::newRow("29") << QTime(1, 2, 3, 456) << "H:m:s.zz" << "1:2:3.456456"; QTest::newRow("30") << QTime(1, 2, 3, 456) << "H:m:s.zzz" << "1:2:3.456"; - QTest::newRow("31") << QTime(1, 2, 3, 4) << "H:m:s.z" << "1:2:3.4"; - QTest::newRow("32") << QTime(1, 2, 3, 4) << "H:m:s.zzz" << "1:2:3.004"; - QTest::newRow("33") << QTime() << "H:m:s.zzz" << ""; - QTest::newRow("34") << QTime(1, 2, 3, 4) << "dd MM yyyy H:m:s.zzz" << "dd MM yyyy 1:2:3.004"; + QTest::newRow("31") << QTime(1, 2, 3, 400) << "H:m:s.z" << "1:2:3.4"; + QTest::newRow("32") << QTime(1, 2, 3, 4) << "H:m:s.z" << "1:2:3.004"; + QTest::newRow("33") << QTime(1, 2, 3, 4) << "H:m:s.zzz" << "1:2:3.004"; + QTest::newRow("34") << QTime() << "H:m:s.zzz" << ""; + QTest::newRow("35") << QTime(1, 2, 3, 4) << "dd MM yyyy H:m:s.zzz" << "dd MM yyyy 1:2:3.004"; } void tst_QLocale::formatTime() @@ -1542,10 +1543,12 @@ void tst_QLocale::toDateTime_data() << "d/M/yyyy hh:h:mm" << "1/12/1974 05:5:14"; QTest::newRow("2C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 0, 0)) << "d/M/yyyyy h" << "1/12/1974y 15"; - QTest::newRow("4C") << "C" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0)) - << "d/M/yyyy zzz" << "1/1/1974 000"; - QTest::newRow("5C") << "C" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0)) - << "dd/MM/yyy z" << "01/01/74y 0"; + QTest::newRow("4C") << "C" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0, 1)) + << "d/M/yyyy zzz" << "1/1/1974 001"; + QTest::newRow("5C") << "C" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0, 1)) + << "dd/MM/yyy z" << "01/01/74y 001"; + QTest::newRow("5Cbis") << "C" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0, 100)) + << "dd/MM/yyy z" << "01/01/74y 1"; QTest::newRow("8C") << "C" << QDateTime(QDate(1974, 12, 2), QTime(0, 0, 13)) << "ddddd/MMMMM/yy ss" << "Monday2/December12/74 13"; QTest::newRow("9C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(0, 0, 13)) diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp index 71bf39fc4e..162047b537 100644 --- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp @@ -560,6 +560,8 @@ void tst_QTime::fromStringFormat_data() QTest::newRow("data9") << QString("2221") << QString("hhhh") << invalidTime(); QTest::newRow("data10") << QString("02:23PM") << QString("hh:mmAP") << QTime(14,23,0,0); QTest::newRow("data11") << QString("02:23pm") << QString("hh:mmap") << QTime(14,23,0,0); + QTest::newRow("short-msecs-lt100") << QString("10:12:34:045") << QString("hh:m:ss:z") << QTime(10,12,34,45); + QTest::newRow("short-msecs-gt100") << QString("10:12:34:45") << QString("hh:m:ss:z") << QTime(10,12,34,450); } void tst_QTime::fromStringFormat() @@ -711,12 +713,13 @@ void tst_QTime::toStringFormat_data() QTest::addColumn("format"); QTest::addColumn("str"); - QTest::newRow( "data0" ) << QTime(0,0,0,0) << QString("h:m:s:z") << QString("0:0:0:0"); - QTest::newRow( "data1" ) << QTime(10,12,34,53) << QString("hh:mm:ss:zzz") << QString("10:12:34:053"); - QTest::newRow( "data2" ) << QTime(10,12,34,45) << QString("hh:m:ss:z") << QString("10:12:34:45"); - QTest::newRow( "data3" ) << QTime(10,12,34,45) << QString("hh:ss ap") << QString("10:34 am"); - QTest::newRow( "data4" ) << QTime(22,12,34,45) << QString("hh:zzz AP") << QString("10:045 PM"); - QTest::newRow( "data5" ) << QTime(230,230,230,230) << QString("hh:mm:ss") << QString(); + QTest::newRow( "midnight" ) << QTime(0,0,0,0) << QString("h:m:s:z") << QString("0:0:0:0"); + QTest::newRow( "full" ) << QTime(10,12,34,53) << QString("hh:mm:ss:zzz") << QString("10:12:34:053"); + QTest::newRow( "short-msecs-lt100" ) << QTime(10,12,34,45) << QString("hh:m:ss:z") << QString("10:12:34:045"); + QTest::newRow( "short-msecs-gt100" ) << QTime(10,12,34,450) << QString("hh:m:ss:z") << QString("10:12:34:45"); + QTest::newRow( "am-pm" ) << QTime(10,12,34,45) << QString("hh:ss ap") << QString("10:34 am"); + QTest::newRow( "AM-PM" ) << QTime(22,12,34,45) << QString("hh:zzz AP") << QString("10:045 PM"); + QTest::newRow( "invalid" ) << QTime(230,230,230,230) << QString("hh:mm:ss") << QString(); } void tst_QTime::toStringFormat() -- cgit v1.2.3