diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2016-10-10 13:44:52 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2016-10-20 15:15:40 +0000 |
commit | 837781db52b59012fdebb357ccb3abbd2f9bf2f5 (patch) | |
tree | 8714373796311c620cfc2af9291a659738e0a77e /tests/auto | |
parent | 6a9e039d19719e489aeaa31d4411f2e19240e0e9 (diff) |
Add Qt::ISODateWithMs date format, with support in QTime/Date/DateTime
The Qt::ISODate format strips milliseconds, so a new format is introduced
that keeps the milliseconds. A new format was chosen over fixing the
existing format due to the behavioral change of suddenly having ms
as part of Qt::ISODate.
Change-Id: If8b852daed068cce8eee9b61a7cd4576bc763443
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/tools/qdate/tst_qdate.cpp | 1 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 26 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qtime/tst_qtime.cpp | 3 |
3 files changed, 22 insertions, 8 deletions
diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp index f22138b795..0e189ba7aa 100644 --- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp @@ -1145,6 +1145,7 @@ void tst_QDate::toStringDateFormat_data() QTest::newRow("year < 0") << QDate(-1,1,1) << Qt::ISODate << QString(); QTest::newRow("year > 9999") << QDate(-1,1,1) << Qt::ISODate << QString(); QTest::newRow("RFC2822Date") << QDate(1974,12,1) << Qt::RFC2822Date << QString("01 Dec 1974"); + QTest::newRow("ISODateWithMs") << QDate(1974,12,1) << Qt::ISODateWithMs << QString("1974-12-01"); } void tst_QDate::toStringDateFormat() diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 0404a276ff..4604e664b0 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -732,46 +732,56 @@ void tst_QDateTime::fromMSecsSinceEpoch() void tst_QDateTime::toString_isoDate_data() { QTest::addColumn<QDateTime>("datetime"); + QTest::addColumn<Qt::DateFormat>("format"); QTest::addColumn<QString>("expected"); QTest::newRow("localtime") << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34)) - << QString("1978-11-09T13:28:34"); + << Qt::ISODate << QString("1978-11-09T13:28:34"); QTest::newRow("UTC") << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), Qt::UTC) - << QString("1978-11-09T13:28:34Z"); + << Qt::ISODate << QString("1978-11-09T13:28:34Z"); QDateTime dt(QDate(1978, 11, 9), QTime(13, 28, 34)); dt.setOffsetFromUtc(19800); QTest::newRow("positive OffsetFromUTC") - << dt + << dt << Qt::ISODate << QString("1978-11-09T13:28:34+05:30"); dt.setUtcOffset(-7200); QTest::newRow("negative OffsetFromUTC") - << dt + << dt << Qt::ISODate << QString("1978-11-09T13:28:34-02:00"); dt.setUtcOffset(-900); QTest::newRow("negative non-integral OffsetFromUTC") - << dt + << dt << Qt::ISODate << QString("1978-11-09T13:28:34-00:15"); QTest::newRow("invalid") << QDateTime(QDate(-1, 11, 9), QTime(13, 28, 34), Qt::UTC) - << QString(); + << Qt::ISODate << QString(); + QTest::newRow("without-ms") + << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34, 20)) + << Qt::ISODate << QString("1978-11-09T13:28:34"); + QTest::newRow("with-ms") + << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34, 20)) + << Qt::ISODateWithMs << QString("1978-11-09T13:28:34.020"); } void tst_QDateTime::toString_isoDate() { QFETCH(QDateTime, datetime); + QFETCH(Qt::DateFormat, format); QFETCH(QString, expected); QLocale oldLocale; QLocale::setDefault(QLocale("en_US")); - QString result = datetime.toString(Qt::ISODate); + QString result = datetime.toString(format); QCOMPARE(result, expected); - QDateTime resultDatetime = QDateTime::fromString(result, Qt::ISODate); + QDateTime resultDatetime = QDateTime::fromString(result, format); // If expecting invalid result the datetime may still be valid, i.e. year < 0 or > 9999 if (!expected.isEmpty()) { + QEXPECT_FAIL("without-ms", "Qt::ISODate truncates milliseconds (QTBUG-56552)", Abort); + QCOMPARE(resultDatetime, datetime); QCOMPARE(resultDatetime.date(), datetime.date()); QCOMPARE(resultDatetime.time(), datetime.time()); diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp index 45af10c3ab..059e1e519b 100644 --- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp @@ -675,6 +675,9 @@ void tst_QTime::toStringDateFormat_data() QTest::newRow("Text 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::TextDate << QString("10:12:34"); QTest::newRow("ISO 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::ISODate << QString("10:12:34"); QTest::newRow("RFC2822Date") << QTime(10, 12, 34, 999) << Qt::RFC2822Date << QString("10:12:34"); + QTest::newRow("ISOWithMs 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::ISODateWithMs << QString("10:12:34.000"); + QTest::newRow("ISOWithMs 10:12:34.020") << QTime(10, 12, 34, 20) << Qt::ISODateWithMs << QString("10:12:34.020"); + QTest::newRow("ISOWithMs 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::ISODateWithMs << QString("10:12:34.999"); } void tst_QTime::toStringDateFormat() |