Modernize string usage in corelib/time/ tests

This incidentally lets me turn on QT_NO_CAST_{FROM,TO}_ASCII for them.

In the process, convert some test-cases to addRow() and use plain QBA
in place of newRow((QString arithmetic).toLocal8Bit().constData()),

Change-Id: I0117338dd927fc4eee74688ac86975508fa43b51
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Edward Welbourne 2025-05-14 17:02:13 +02:00
parent f5d888b44a
commit 6f8431b930
11 changed files with 473 additions and 455 deletions

View File

@ -14,6 +14,11 @@ endif()
qt_internal_add_test(tst_qcalendar
SOURCES
tst_qcalendar.cpp
DEFINES
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_FOREACH
QT_NO_KEYWORDS
LIBRARIES
Qt::CorePrivate
)

View File

@ -7,13 +7,15 @@
#include <private/qgregoriancalendar_p.h>
Q_DECLARE_METATYPE(QCalendar::System)
using namespace Qt::StringLiterals;
class tst_QCalendar : public QObject
{
Q_OBJECT
private:
void checkYear(const QCalendar &cal, int year);
private slots:
private Q_SLOTS:
void basic_data();
void basic();
void unspecified_data() { basic_data(); }
@ -395,8 +397,8 @@ void tst_QCalendar::aliases()
#if QT_CONFIG(islamiccivilcalendar)
// Exercise all constructors from name, while we're at it:
QCOMPARE(QCalendar(u"islamic-civil").name(), u"Islamic Civil");
QCOMPARE(QCalendar(QLatin1String("islamic")).name(), u"Islamic Civil");
QCOMPARE(QCalendar(QStringLiteral("Islamic")).name(), u"Islamic Civil");
QCOMPARE(QCalendar("islamic"_L1).name(), u"Islamic Civil");
QCOMPARE(QCalendar(u"Islamic"_s).name(), u"Islamic Civil");
#endif
// Invalid is handled gracefully:

View File

@ -15,6 +15,8 @@ qt_internal_add_test(tst_qdate
SOURCES
tst_qdate.cpp
DEFINES
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_FOREACH
QT_NO_KEYWORDS
LIBRARIES

View File

@ -1161,38 +1161,38 @@ void tst_QDate::operator_insert_extract_data()
QTest::addColumn<QDate>("date");
QTest::addColumn<QDataStream::Version>("dataStreamVersion");
QMap<QDataStream::Version, QString> versionsToTest;
versionsToTest.insert(QDataStream::Qt_1_0, QString::fromLatin1("Qt_1_0"));
versionsToTest.insert(QDataStream::Qt_2_0, QString::fromLatin1("Qt_2_0"));
versionsToTest.insert(QDataStream::Qt_2_1, QString::fromLatin1("Qt_2_1"));
versionsToTest.insert(QDataStream::Qt_3_0, QString::fromLatin1("Qt_3_0"));
versionsToTest.insert(QDataStream::Qt_3_1, QString::fromLatin1("Qt_3_1"));
versionsToTest.insert(QDataStream::Qt_3_3, QString::fromLatin1("Qt_3_3"));
versionsToTest.insert(QDataStream::Qt_4_0, QString::fromLatin1("Qt_4_0"));
versionsToTest.insert(QDataStream::Qt_4_1, QString::fromLatin1("Qt_4_1"));
versionsToTest.insert(QDataStream::Qt_4_2, QString::fromLatin1("Qt_4_2"));
versionsToTest.insert(QDataStream::Qt_4_3, QString::fromLatin1("Qt_4_3"));
versionsToTest.insert(QDataStream::Qt_4_4, QString::fromLatin1("Qt_4_4"));
versionsToTest.insert(QDataStream::Qt_4_5, QString::fromLatin1("Qt_4_5"));
versionsToTest.insert(QDataStream::Qt_4_6, QString::fromLatin1("Qt_4_6"));
versionsToTest.insert(QDataStream::Qt_4_7, QString::fromLatin1("Qt_4_7"));
versionsToTest.insert(QDataStream::Qt_4_8, QString::fromLatin1("Qt_4_8"));
versionsToTest.insert(QDataStream::Qt_4_9, QString::fromLatin1("Qt_4_9"));
versionsToTest.insert(QDataStream::Qt_5_0, QString::fromLatin1("Qt_5_0"));
QMap<QDataStream::Version, QByteArray> versionsToTest;
versionsToTest.insert(QDataStream::Qt_1_0, "Qt_1_0"_ba);
versionsToTest.insert(QDataStream::Qt_2_0, "Qt_2_0"_ba);
versionsToTest.insert(QDataStream::Qt_2_1, "Qt_2_1"_ba);
versionsToTest.insert(QDataStream::Qt_3_0, "Qt_3_0"_ba);
versionsToTest.insert(QDataStream::Qt_3_1, "Qt_3_1"_ba);
versionsToTest.insert(QDataStream::Qt_3_3, "Qt_3_3"_ba);
versionsToTest.insert(QDataStream::Qt_4_0, "Qt_4_0"_ba);
versionsToTest.insert(QDataStream::Qt_4_1, "Qt_4_1"_ba);
versionsToTest.insert(QDataStream::Qt_4_2, "Qt_4_2"_ba);
versionsToTest.insert(QDataStream::Qt_4_3, "Qt_4_3"_ba);
versionsToTest.insert(QDataStream::Qt_4_4, "Qt_4_4"_ba);
versionsToTest.insert(QDataStream::Qt_4_5, "Qt_4_5"_ba);
versionsToTest.insert(QDataStream::Qt_4_6, "Qt_4_6"_ba);
versionsToTest.insert(QDataStream::Qt_4_7, "Qt_4_7"_ba);
versionsToTest.insert(QDataStream::Qt_4_8, "Qt_4_8"_ba);
versionsToTest.insert(QDataStream::Qt_4_9, "Qt_4_9"_ba);
versionsToTest.insert(QDataStream::Qt_5_0, "Qt_5_0"_ba);
for (QMap<QDataStream::Version, QString>::ConstIterator it = versionsToTest.constBegin();
it != versionsToTest.constEnd(); ++it) {
const QString &version(it.value());
QTest::newRow(("(invalid) " + version).toLocal8Bit().constData()) << invalidDate() << it.key();
QTest::newRow(("(1, 1, 1) " + version).toLocal8Bit().constData()) << QDate(1, 1, 1) << it.key();
QTest::newRow(("(-1, 1, 1) " + version).toLocal8Bit().constData()) << QDate(-1, 1, 1) << it.key();
QTest::newRow(("(1995, 5, 20) " + version).toLocal8Bit().constData()) << QDate(1995, 5, 20) << it.key();
for (auto it = versionsToTest.constBegin(); it != versionsToTest.constEnd(); ++it) {
const QByteArray &version(it.value());
const char *const tag = version.constData();
QTest::addRow("(invalid) %s", tag) << invalidDate() << it.key();
QTest::addRow("(1, 1, 1) %s", tag) << QDate(1, 1, 1) << it.key();
QTest::addRow("(-1, 1, 1) %s", tag) << QDate(-1, 1, 1) << it.key();
QTest::addRow("(1995, 5, 20) %s", tag) << QDate(1995, 5, 20) << it.key();
// Test minimums for quint32/qint64.
if (it.key() >= QDataStream::Qt_5_0)
QTest::newRow(("(-4714, 11, 24) " + version).toLocal8Bit().constData()) << QDate(-4714, 11, 24) << it.key();
QTest::addRow("(-4714, 11, 24) %s", tag) << QDate(-4714, 11, 24) << it.key();
else
QTest::newRow(("(-4713, 1, 2) " + version).toLocal8Bit().constData()) << QDate(-4713, 1, 2) << it.key();
QTest::addRow("(-4713, 1, 2) %s", tag) << QDate(-4713, 1, 2) << it.key();
}
}
@ -1220,113 +1220,113 @@ void tst_QDate::fromStringDateFormat_data()
QTest::addColumn<Qt::DateFormat>("dateFormat");
QTest::addColumn<QDate>("expectedDate");
QTest::newRow("text0") << QString("Sat May 20 1995") << Qt::TextDate << QDate(1995, 5, 20);
QTest::newRow("text1") << QString("Tue Dec 17 2002") << Qt::TextDate << QDate(2002, 12, 17);
QTest::newRow("text0") << u"Sat May 20 1995"_s << Qt::TextDate << QDate(1995, 5, 20);
QTest::newRow("text1") << u"Tue Dec 17 2002"_s << Qt::TextDate << QDate(2002, 12, 17);
QTest::newRow("text2") << QDate(1999, 11, 14).toString(Qt::TextDate) << Qt::TextDate << QDate(1999, 11, 14);
QTest::newRow("text3") << QString("xxx Jan 1 0999") << Qt::TextDate << QDate(999, 1, 1);
QTest::newRow("text3b") << QString("xxx Jan 1 999") << Qt::TextDate << QDate(999, 1, 1);
QTest::newRow("text4") << QString("xxx Jan 1 12345") << Qt::TextDate << QDate(12345, 1, 1);
QTest::newRow("text5") << QString("xxx Jan 1 -0001") << Qt::TextDate << QDate(-1, 1, 1);
QTest::newRow("text6") << QString("xxx Jan 1 -4712") << Qt::TextDate << QDate(-4712, 1, 1);
QTest::newRow("text7") << QString("xxx Nov 25 -4713") << Qt::TextDate << QDate(-4713, 11, 25);
QTest::newRow("text3") << u"xxx Jan 1 0999"_s << Qt::TextDate << QDate(999, 1, 1);
QTest::newRow("text3b") << u"xxx Jan 1 999"_s << Qt::TextDate << QDate(999, 1, 1);
QTest::newRow("text4") << u"xxx Jan 1 12345"_s << Qt::TextDate << QDate(12345, 1, 1);
QTest::newRow("text5") << u"xxx Jan 1 -0001"_s << Qt::TextDate << QDate(-1, 1, 1);
QTest::newRow("text6") << u"xxx Jan 1 -4712"_s << Qt::TextDate << QDate(-4712, 1, 1);
QTest::newRow("text7") << u"xxx Nov 25 -4713"_s << Qt::TextDate << QDate(-4713, 11, 25);
QTest::newRow("text, empty") << QString() << Qt::TextDate << QDate();
QTest::newRow("text, 3 part") << QString("part1 part2 part3") << Qt::TextDate << QDate();
QTest::newRow("text, invalid month name") << QString("Wed BabytownFrolics 8 2012") << Qt::TextDate << QDate();
QTest::newRow("text, invalid day") << QString("Wed May Wilhelm 2012") << Qt::TextDate << QDate();
QTest::newRow("text, invalid year") << QString("Wed May 8 Cats") << Qt::TextDate << QDate();
QTest::newRow("text, 3 part") << u"part1 part2 part3"_s << Qt::TextDate << QDate();
QTest::newRow("text, invalid month name") << u"Wed BabytownFrolics 8 2012"_s << Qt::TextDate << QDate();
QTest::newRow("text, invalid day") << u"Wed May Wilhelm 2012"_s << Qt::TextDate << QDate();
QTest::newRow("text, invalid year") << u"Wed May 8 Cats"_s << Qt::TextDate << QDate();
QTest::newRow("iso0") << QString("1995-05-20") << Qt::ISODate << QDate(1995, 5, 20);
QTest::newRow("iso1") << QString("2002-12-17") << Qt::ISODate << QDate(2002, 12, 17);
QTest::newRow("iso0") << u"1995-05-20"_s << Qt::ISODate << QDate(1995, 5, 20);
QTest::newRow("iso1") << u"2002-12-17"_s << Qt::ISODate << QDate(2002, 12, 17);
QTest::newRow("iso2") << QDate(1999, 11, 14).toString(Qt::ISODate) << Qt::ISODate << QDate(1999, 11, 14);
QTest::newRow("iso3") << QString("0999-01-01") << Qt::ISODate << QDate(999, 1, 1);
QTest::newRow("iso3b") << QString("0999-01-01") << Qt::ISODate << QDate(999, 1, 1);
QTest::newRow("iso4") << QString("2000101101") << Qt::ISODate << QDate();
QTest::newRow("iso5") << QString("2000/01/01") << Qt::ISODate << QDate(2000, 1, 1);
QTest::newRow("iso6") << QString("2000-01-01 blah") << Qt::ISODate << QDate(2000, 1, 1);
QTest::newRow("iso7") << QString("2000-01-011blah") << Qt::ISODate << QDate();
QTest::newRow("iso8") << QString("2000-01-01blah") << Qt::ISODate << QDate(2000, 1, 1);
QTest::newRow("iso9") << QString("-001-01-01") << Qt::ISODate << QDate();
QTest::newRow("iso10") << QString("99999-01-01") << Qt::ISODate << QDate();
QTest::newRow("iso-yr-0") << QString("0000-01-01") << Qt::ISODate << QDate();
QTest::newRow("iso3") << u"0999-01-01"_s << Qt::ISODate << QDate(999, 1, 1);
QTest::newRow("iso3b") << u"0999-01-01"_s << Qt::ISODate << QDate(999, 1, 1);
QTest::newRow("iso4") << u"2000101101"_s << Qt::ISODate << QDate();
QTest::newRow("iso5") << u"2000/01/01"_s << Qt::ISODate << QDate(2000, 1, 1);
QTest::newRow("iso6") << u"2000-01-01 blah"_s << Qt::ISODate << QDate(2000, 1, 1);
QTest::newRow("iso7") << u"2000-01-011blah"_s << Qt::ISODate << QDate();
QTest::newRow("iso8") << u"2000-01-01blah"_s << Qt::ISODate << QDate(2000, 1, 1);
QTest::newRow("iso9") << u"-001-01-01"_s << Qt::ISODate << QDate();
QTest::newRow("iso10") << u"99999-01-01"_s << Qt::ISODate << QDate();
QTest::newRow("iso-yr-0") << u"0000-01-01"_s << Qt::ISODate << QDate();
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
QTest::newRow("RFC 2822") << u"13 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDate(1987, 2, 13);
QTest::newRow("RFC 2822 after space")
<< QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
<< u" 13 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDate(1987, 2, 13);
QTest::newRow("RFC 2822 with day") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
QTest::newRow("RFC 2822 with day") << u"Thu, 01 Jan 1970 00:12:34 +0000"_s
<< Qt::RFC2822Date << epochDate();
QTest::newRow("RFC 2822 with day after space")
<< QString::fromLatin1(" Thu, 01 Jan 1970 00:12:34 +0000")
<< u" Thu, 01 Jan 1970 00:12:34 +0000"_s
<< Qt::RFC2822Date << epochDate();
// No timezone
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
QTest::newRow("RFC 2822 no timezone") << u"01 Jan 1970 00:12:34"_s
<< Qt::RFC2822Date << epochDate();
// No time specified
QTest::newRow("RFC 2822 date only") << QString::fromLatin1("01 Nov 2002")
QTest::newRow("RFC 2822 date only") << u"01 Nov 2002"_s
<< Qt::RFC2822Date << QDate(2002, 11, 1);
QTest::newRow("RFC 2822 with day date only") << QString::fromLatin1("Fri, 01 Nov 2002")
QTest::newRow("RFC 2822 with day date only") << u"Fri, 01 Nov 2002"_s
<< Qt::RFC2822Date << QDate(2002, 11, 1);
QTest::newRow("RFC 2822 malformed time")
<< QString::fromLatin1("01 Nov 2002 0:") << Qt::RFC2822Date << QDate();
<< u"01 Nov 2002 0:"_s << Qt::RFC2822Date << QDate();
// Test invalid month, day, year
QTest::newRow("RFC 2822 invalid month name") << QString::fromLatin1("13 Fev 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid month name") << u"13 Fev 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid day") << QString::fromLatin1("36 Fev 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid day") << u"36 Fev 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid year") << u"13 Fev 0000 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid character at end")
<< QString::fromLatin1("01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << QDate();
<< u"01 Jan 2012 08:00:00 +0100!"_s << Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid character at front")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate();
<< u"!01 Jan 2012 08:00:00 +0100"_s << Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid character both ends")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << QDate();
<< u"!01 Jan 2012 08:00:00 +0100!"_s << Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid character at front, 2 at back")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..") << Qt::RFC2822Date << QDate();
<< u"!01 Jan 2012 08:00:00 +0100.."_s << Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid character 2 at front")
<< QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate();
<< u"!!01 Jan 2012 08:00:00 +0100"_s << Qt::RFC2822Date << QDate();
// The common date text used by the "invalid character" tests, just to be
// sure *it's* not what's invalid:
QTest::newRow("RFC 2822 (not invalid)")
<< QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
<< u"01 Jan 2012 08:00:00 +0100"_s
<< Qt::RFC2822Date << QDate(2012, 1, 1);
// Test Qt::RFC2822Date format (RFC 850 and 1036, permissive).
QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100")
QTest::newRow("RFC 850 and 1036") << u"Fri Feb 13 13:24:51 1987 +0100"_s
<< Qt::RFC2822Date << QDate(1987, 2, 13);
QTest::newRow("RFC 850 and 1036 after space")
<< QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
<< u" Fri Feb 13 13:24:51 1987 +0100"_s
<< Qt::RFC2822Date << QDate(1987, 2, 13);
// No timezone
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
QTest::newRow("RFC 850 and 1036 no timezone") << u"Thu Jan 01 00:12:34 1970"_s
<< Qt::RFC2822Date << epochDate();
// No time specified
QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002")
QTest::newRow("RFC 850 and 1036 date only") << u"Fri Nov 01 2002"_s
<< Qt::RFC2822Date << QDate(2002, 11, 1);
// Test invalid characters.
QTest::newRow("RFC 850 and 1036 invalid character at end")
<< QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
<< u"Sun Jan 01 08:00:00 2012 +0100!"_s
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 850 and 1036 invalid character at front")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100")
<< u"!Sun Jan 01 08:00:00 2012 +0100"_s
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 850 and 1036 invalid character both ends")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!")
<< u"!Sun Jan 01 08:00:00 2012 +0100!"_s
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..")
<< u"!Sun Jan 01 08:00:00 2012 +0100.."_s
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 850 and 1036 invalid character 2 at front")
<< QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0100")
<< u"!!Sun Jan 01 08:00:00 2012 +0100"_s
<< Qt::RFC2822Date << QDate();
// Again, check the text in the "invalid character" tests isn't the source of invalidity:
QTest::newRow("RFC 850 and 1036 (not invalid)")
<< QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100")
<< u"Sun Jan 01 08:00:00 2012 +0100"_s
<< Qt::RFC2822Date << QDate(2012, 1, 1);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << QDate();
QTest::newRow("RFC empty") << u""_s << Qt::RFC2822Date << QDate();
}
void tst_QDate::fromStringDateFormat()
@ -1426,15 +1426,15 @@ void tst_QDate::fromStringFormat_data()
// Test unicode handling.
QTest::newRow("Unicode in format string")
<< QString(u8"2020🤣09🤣21") << QString(u8"yyyy🤣MM🤣dd") << 1900 << QDate(2020, 9, 21);
<< u"2020🤣09🤣21"_s << u"yyyy🤣MM🤣dd"_s << 1900 << QDate(2020, 9, 21);
QTest::newRow("Unicode-in-format-string-quoted-emoji")
<< QString(u8"🤣🤣2020👍09🤣21") << QString(u8"'🤣🤣'yyyy👍MM🤣dd") << 1900
<< u"🤣🤣2020👍09🤣21"_s << u"'🤣🤣'yyyy👍MM🤣dd"_s << 1900
<< QDate(2020, 9, 21);
QTest::newRow("Unicode-in-quoted-dd-format-string")
<< QString(u8"🤣🤣2020👍09🤣21dd") << QString(u8"🤣🤣yyyy👍MM🤣dd'dd'") << 1900
<< u"🤣🤣2020👍09🤣21dd"_s << u"🤣🤣yyyy👍MM🤣dd'dd'"_s << 1900
<< QDate(2020, 9, 21);
QTest::newRow("Unicode-in-all-formats-quoted-string")
<< QString(u8"🤣🤣yyyy2020👍MM09🤣21dd") << QString(u8"🤣🤣'yyyy'yyyy👍'MM'MM🤣dd'dd'")
<< u"🤣🤣yyyy2020👍MM09🤣21dd"_s << u"🤣🤣'yyyy'yyyy👍'MM'MM🤣dd'dd'"_s
<< 1900 << QDate(2020, 9, 21);
// QTBUG-84334
@ -1541,11 +1541,11 @@ void tst_QDate::toStringFormat_data()
QTest::addColumn<QString>("format");
QTest::addColumn<QString>("str");
QTest::newRow( "data0" ) << QDate(1995,5,20) << QString("d-M-yy") << QString("20-5-95");
QTest::newRow( "data1" ) << QDate(2002,12,17) << QString("dd-MM-yyyy") << QString("17-12-2002");
QTest::newRow( "data2" ) << QDate(1995,5,20) << QString("M-yy") << QString("5-95");
QTest::newRow( "data3" ) << QDate(2002,12,17) << QString("dd") << QString("17");
QTest::newRow( "data4" ) << QDate() << QString("dd-mm-yyyy") << QString();
QTest::newRow( "data0" ) << QDate(1995,5,20) << u"d-M-yy"_s << u"20-5-95"_s;
QTest::newRow( "data1" ) << QDate(2002,12,17) << u"dd-MM-yyyy"_s << u"17-12-2002"_s;
QTest::newRow( "data2" ) << QDate(1995,5,20) << u"M-yy"_s << u"5-95"_s;
QTest::newRow( "data3" ) << QDate(2002,12,17) << u"dd"_s << u"17"_s;
QTest::newRow( "data4" ) << QDate() << u"dd-mm-yyyy"_s << QString();
}
void tst_QDate::toStringFormat()
@ -1563,14 +1563,14 @@ void tst_QDate::toStringDateFormat_data()
QTest::addColumn<Qt::DateFormat>("format");
QTest::addColumn<QString>("expectedStr");
QTest::newRow("data0") << QDate(1,1,1) << Qt::ISODate << QString("0001-01-01");
QTest::newRow("data1") << QDate(11,1,1) << Qt::ISODate << QString("0011-01-01");
QTest::newRow("data2") << QDate(111,1,1) << Qt::ISODate << QString("0111-01-01");
QTest::newRow("data3") << QDate(1974,12,1) << Qt::ISODate << QString("1974-12-01");
QTest::newRow("data0") << QDate(1,1,1) << Qt::ISODate << u"0001-01-01"_s;
QTest::newRow("data1") << QDate(11,1,1) << Qt::ISODate << u"0011-01-01"_s;
QTest::newRow("data2") << QDate(111,1,1) << Qt::ISODate << u"0111-01-01"_s;
QTest::newRow("data3") << QDate(1974,12,1) << Qt::ISODate << u"1974-12-01"_s;
QTest::newRow("year < 0") << QDate(-1,1,1) << Qt::ISODate << QString();
QTest::newRow("year > 9999") << QDate(10000, 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");
QTest::newRow("RFC2822Date") << QDate(1974,12,1) << Qt::RFC2822Date << u"01 Dec 1974"_s;
QTest::newRow("ISODateWithMs") << QDate(1974,12,1) << Qt::ISODateWithMs << u"1974-12-01"_s;
}
void tst_QDate::toStringDateFormat()
@ -1670,10 +1670,10 @@ void tst_QDate::printNegativeYear_data() const
{
QTest::addColumn<int>("year");
QTest::addColumn<QString>("expect");
QTest::newRow("millennium") << -1000 << QStringLiteral("-1000");
QTest::newRow("century") << -500 << QStringLiteral("-0500");
QTest::newRow("decade") << -20 << QStringLiteral("-0020");
QTest::newRow("year") << -7 << QStringLiteral("-0007");
QTest::newRow("millennium") << -1000 << u"-1000"_s;
QTest::newRow("century") << -500 << u"-0500"_s;
QTest::newRow("decade") << -20 << u"-0020"_s;
QTest::newRow("year") << -7 << u"-0007"_s;
}
void tst_QDate::printNegativeYear() const
@ -1685,7 +1685,7 @@ void tst_QDate::printNegativeYear() const
QDate date(year, 3, 4);
QVERIFY(date.isValid());
QCOMPARE(date.year(), year);
QCOMPARE(date.toString(QLatin1String("yyyy")), expect);
QCOMPARE(date.toString(u"yyyy"), expect);
}
#if QT_CONFIG(datestring)

View File

@ -15,6 +15,8 @@ qt_internal_add_test(tst_qdatetime
SOURCES
tst_qdatetime.cpp
DEFINES
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_FOREACH
QT_NO_KEYWORDS
LIBRARIES

View File

@ -1034,32 +1034,32 @@ void tst_QDateTime::toString_isoDate_data()
QTest::newRow("localtime")
<< QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34))
<< Qt::ISODate << QString("1978-11-09T13:28:34");
<< Qt::ISODate << u"1978-11-09T13:28:34"_s;
QTest::newRow("UTC")
<< QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), UTC)
<< Qt::ISODate << QString("1978-11-09T13:28:34Z");
<< Qt::ISODate << u"1978-11-09T13:28:34Z"_s;
QDateTime dt(QDate(1978, 11, 9), QTime(13, 28, 34));
dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(19800));
QTest::newRow("positive OffsetFromUTC")
<< dt << Qt::ISODate
<< QString("1978-11-09T13:28:34+05:30");
<< u"1978-11-09T13:28:34+05:30"_s;
dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-7200));
QTest::newRow("negative OffsetFromUTC")
<< dt << Qt::ISODate
<< QString("1978-11-09T13:28:34-02:00");
<< u"1978-11-09T13:28:34-02:00"_s;
dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-900));
QTest::newRow("negative non-integral OffsetFromUTC")
<< dt << Qt::ISODate
<< QString("1978-11-09T13:28:34-00:15");
<< u"1978-11-09T13:28:34-00:15"_s;
QTest::newRow("invalid") // ISODate < 2019 doesn't allow -ve year numbers; QTBUG-91070
<< QDateTime(QDate(-1, 11, 9), QTime(13, 28, 34), UTC)
<< 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");
<< Qt::ISODate << u"1978-11-09T13:28:34"_s;
QTest::newRow("with-ms")
<< QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34, 20))
<< Qt::ISODateWithMs << QString("1978-11-09T13:28:34.020");
<< Qt::ISODateWithMs << u"1978-11-09T13:28:34.020"_s;
}
void tst_QDateTime::toString_isoDate()
@ -1090,19 +1090,19 @@ void tst_QDateTime::toString_isoDate()
void tst_QDateTime::toString_isoDate_extra()
{
QDateTime dt = QDateTime::fromMSecsSinceEpoch(0, UTC);
QCOMPARE(dt.toString(Qt::ISODate), QLatin1String("1970-01-01T00:00:00Z"));
QCOMPARE(dt.toString(Qt::ISODate), u"1970-01-01T00:00:00Z");
#if QT_CONFIG(timezone)
QTimeZone PST("America/Vancouver");
if (PST.isValid()) {
dt = QDateTime::fromMSecsSinceEpoch(0, PST);
QCOMPARE(dt.toString(Qt::ISODate), QLatin1String("1969-12-31T16:00:00-08:00"));
QCOMPARE(dt.toString(Qt::ISODate), u"1969-12-31T16:00:00-08:00");
} else {
qDebug("Missed zone test: no America/Vancouver zone available");
}
QTimeZone CET("Europe/Berlin");
if (CET.isValid()) {
dt = QDateTime::fromMSecsSinceEpoch(0, CET);
QCOMPARE(dt.toString(Qt::ISODate), QLatin1String("1970-01-01T01:00:00+01:00"));
QCOMPARE(dt.toString(Qt::ISODate), u"1970-01-01T01:00:00+01:00");
} else {
qDebug("Missed zone test: no Europe/Berlin zone available");
}
@ -1115,21 +1115,21 @@ void tst_QDateTime::toString_textDate_data()
QTest::addColumn<QString>("expected");
const QString wednesdayJanuary = QLocale::c().dayName(3, QLocale::ShortFormat)
+ ' ' + QLocale::c().monthName(1, QLocale::ShortFormat);
+ u' ' + QLocale::c().monthName(1, QLocale::ShortFormat);
// ### Qt 7 GMT: change to UTC - see matching QDateTime::fromString() comment
QTest::newRow("localtime") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3))
<< wednesdayJanuary + QString(" 2 01:02:03 2013");
<< wednesdayJanuary + u" 2 01:02:03 2013"_s;
QTest::newRow("utc") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3), UTC)
<< wednesdayJanuary + QString(" 2 01:02:03 2013 GMT");
<< wednesdayJanuary + u" 2 01:02:03 2013 GMT"_s;
QTest::newRow("offset+") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3),
QTimeZone::fromSecondsAheadOfUtc(10 * 60 * 60))
<< wednesdayJanuary + QString(" 2 01:02:03 2013 GMT+1000");
<< wednesdayJanuary + u" 2 01:02:03 2013 GMT+1000"_s;
QTest::newRow("offset-") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3),
QTimeZone::fromSecondsAheadOfUtc(-10 * 60 * 60))
<< wednesdayJanuary + QString(" 2 01:02:03 2013 GMT-1000");
<< wednesdayJanuary + u" 2 01:02:03 2013 GMT-1000"_s;
QTest::newRow("invalid") << QDateTime()
<< QString("");
<< u""_s;
}
void tst_QDateTime::toString_textDate()
@ -1154,7 +1154,7 @@ void tst_QDateTime::toString_textDate_extra()
{
// ### Qt 7 GMT: change to UTC - see matching QDateTime::fromString() comment
auto endsWithGmt = [](const QDateTime &dt) {
return dt.toString().endsWith(QLatin1String("GMT"));
return dt.toString().endsWith(u"GMT");
};
QDateTime dt = QDateTime::fromMSecsSinceEpoch(0);
QVERIFY(!endsWithGmt(dt));
@ -1163,14 +1163,14 @@ void tst_QDateTime::toString_textDate_extra()
#if QT_CONFIG(timezone)
if (QTimeZone::systemTimeZone().offsetFromUtc(dt))
QCOMPARE_NE(dt.toString(), QLatin1String("Thu Jan 1 00:00:00 1970"));
QCOMPARE_NE(dt.toString(), u"Thu Jan 1 00:00:00 1970");
else
QCOMPARE(dt.toString(), QLatin1String("Thu Jan 1 00:00:00 1970"));
QCOMPARE(dt.toString(), u"Thu Jan 1 00:00:00 1970");
QTimeZone PST("America/Vancouver");
if (PST.isValid()) {
dt = QDateTime::fromMSecsSinceEpoch(0, PST);
QCOMPARE(dt.toString(), QLatin1String("Wed Dec 31 16:00:00 1969 UTC-08:00"));
QCOMPARE(dt.toString(), u"Wed Dec 31 16:00:00 1969 UTC-08:00");
dt = dt.toLocalTime();
QVERIFY(!endsWithGmt(dt));
} else {
@ -1179,7 +1179,7 @@ void tst_QDateTime::toString_textDate_extra()
QTimeZone CET("Europe/Berlin");
if (CET.isValid()) {
dt = QDateTime::fromMSecsSinceEpoch(0, CET);
QCOMPARE(dt.toString(), QLatin1String("Thu Jan 1 01:00:00 1970 UTC+01:00"));
QCOMPARE(dt.toString(), u"Thu Jan 1 01:00:00 1970 UTC+01:00");
dt = dt.toLocalTime();
QVERIFY(!endsWithGmt(dt));
} else {
@ -1187,9 +1187,9 @@ void tst_QDateTime::toString_textDate_extra()
}
#else // timezone
if (dt.offsetFromUtc())
QCOMPARE_NE(dt.toString(), QLatin1String("Thu Jan 1 00:00:00 1970"));
QCOMPARE_NE(dt.toString(), u"Thu Jan 1 00:00:00 1970");
else
QCOMPARE(dt.toString(), QLatin1String("Thu Jan 1 00:00:00 1970"));
QCOMPARE(dt.toString(), u"Thu Jan 1 00:00:00 1970");
#endif
dt = QDateTime::fromMSecsSinceEpoch(0, UTC);
QVERIFY(endsWithGmt(dt));
@ -1203,26 +1203,26 @@ void tst_QDateTime::toString_rfcDate_data()
if (zoneIsCET) {
QTest::newRow("localtime")
<< QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34))
<< QString("09 Nov 1978 13:28:34 +0100");
<< u"09 Nov 1978 13:28:34 +0100"_s;
}
QTest::newRow("UTC")
<< QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), UTC)
<< QString("09 Nov 1978 13:28:34 +0000");
<< u"09 Nov 1978 13:28:34 +0000"_s;
QDateTime dt(QDate(1978, 11, 9), QTime(13, 28, 34));
dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(19800));
QTest::newRow("positive OffsetFromUTC")
<< dt
<< QString("09 Nov 1978 13:28:34 +0530");
<< u"09 Nov 1978 13:28:34 +0530"_s;
dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-7200));
QTest::newRow("negative OffsetFromUTC")
<< dt
<< QString("09 Nov 1978 13:28:34 -0200");
<< u"09 Nov 1978 13:28:34 -0200"_s;
QTest::newRow("invalid")
<< QDateTime(QDate(1978, 13, 9), QTime(13, 28, 34), UTC)
<< QString();
QTest::newRow("999 milliseconds UTC")
<< QDateTime(QDate(2000, 1, 1), QTime(13, 28, 34, 999), UTC)
<< QString("01 Jan 2000 13:28:34 +0000");
<< u"01 Jan 2000 13:28:34 +0000"_s;
}
void tst_QDateTime::toString_rfcDate()
@ -1232,7 +1232,7 @@ void tst_QDateTime::toString_rfcDate()
// Set to non-English locale to confirm still uses English
QLocale oldLocale;
QLocale::setDefault(QLocale("de_DE"));
QLocale::setDefault(QLocale(u"de_DE"));
QString actual(dt.toString(Qt::RFC2822Date));
QLocale::setDefault(oldLocale);
QCOMPARE(actual, formatted);
@ -1246,7 +1246,7 @@ void tst_QDateTime::toString_enumformat()
QVERIFY(!str1.isEmpty()); // It's locale-dependent everywhere
QString str2 = dt1.toString(Qt::ISODate);
QCOMPARE(str2, QString("1995-05-20T12:34:56"));
QCOMPARE(str2, u"1995-05-20T12:34:56"_s);
}
void tst_QDateTime::toString_strformat()
@ -1255,12 +1255,12 @@ void tst_QDateTime::toString_strformat()
QDate testDate(2013, 1, 1);
QTime testTime(1, 2, 3, 456);
QDateTime testDateTime(testDate, testTime, UTC);
QCOMPARE(testDate.toString("yyyy-MM-dd"), QString("2013-01-01"));
QCOMPARE(testTime.toString("hh:mm:ss"), QString("01:02:03"));
QCOMPARE(testTime.toString("hh:mm:ss.zz"), QString("01:02:03.456"));
QCOMPARE(testDateTime.toString("yyyy-MM-dd hh:mm:ss t"), QString("2013-01-01 01:02:03 UTC"));
QCOMPARE(testDateTime.toString("yyyy-MM-dd hh:mm:ss tt"), QString("2013-01-01 01:02:03 +0000"));
QCOMPARE(testDateTime.toString("yyyy-MM-dd hh:mm:ss ttt"), QString("2013-01-01 01:02:03 +00:00"));
QCOMPARE(testDate.toString(u"yyyy-MM-dd"), u"2013-01-01"_s);
QCOMPARE(testTime.toString(u"hh:mm:ss"), u"01:02:03"_s);
QCOMPARE(testTime.toString(u"hh:mm:ss.zz"), u"01:02:03.456"_s);
QCOMPARE(testDateTime.toString(u"yyyy-MM-dd hh:mm:ss t"), u"2013-01-01 01:02:03 UTC"_s);
QCOMPARE(testDateTime.toString(u"yyyy-MM-dd hh:mm:ss tt"), u"2013-01-01 01:02:03 +0000"_s);
QCOMPARE(testDateTime.toString(u"yyyy-MM-dd hh:mm:ss ttt"), u"2013-01-01 01:02:03 +00:00"_s);
#if QT_CONFIG(icu) && !defined(Q_STL_DINKUMWARE)
// The Dinkum (VxWorks) exception may just be because it has an old ICU.
@ -1944,8 +1944,8 @@ void tst_QDateTime::toUTC_extra()
QDateTime dt = QDateTime::currentDateTime();
if (dt.time().msec() == 0)
dt.setTime(dt.time().addMSecs(1));
QString s = dt.toString("zzz");
QString t = dt.toUTC().toString("zzz");
QString s = dt.toString(u"zzz");
QString t = dt.toUTC().toString(u"zzz");
QCOMPARE(s, t);
}
QT_WARNING_POP
@ -2381,8 +2381,8 @@ void tst_QDateTime::springForward_data()
#if !QT_CONFIG(timezone)
} else {
// Includes the numbers you need to test for your zone, as above:
QString msg(QString::fromLatin1("No spring forward test data for this TZ (%1, %2)"
).arg(winter).arg(summer));
QString msg("No spring forward test data for this TZ (%1, %2)"_L1.arg(
QString::number(winter), QString::number(summer)));
QSKIP(qPrintable(msg));
#endif
}
@ -2757,193 +2757,193 @@ void tst_QDateTime::fromStringDateFormat_data()
const bool goodEpochStart = QDateTime(QDate(1970, 1, 1), QTime(0, 0)).isValid();
// Test Qt::TextDate format.
QTest::newRow("text date") << QString::fromLatin1("Tue Jun 17 08:00:10 2003")
QTest::newRow("text date") << u"Tue Jun 17 08:00:10 2003"_s
<< Qt::TextDate << QDateTime(QDate(2003, 6, 17), QTime(8, 0, 10));
QTest::newRow("text date Year 0999") << QString::fromLatin1("Tue Jun 17 08:00:10 0999")
QTest::newRow("text date Year 0999") << u"Tue Jun 17 08:00:10 0999"_s
<< Qt::TextDate << QDateTime(QDate(999, 6, 17), QTime(8, 0, 10));
QTest::newRow("text date Year 999") << QString::fromLatin1("Tue Jun 17 08:00:10 999")
QTest::newRow("text date Year 999") << u"Tue Jun 17 08:00:10 999"_s
<< Qt::TextDate << QDateTime(QDate(999, 6, 17), QTime(8, 0, 10));
QTest::newRow("text date Year 12345") << QString::fromLatin1("Tue Jun 17 08:00:10 12345")
QTest::newRow("text date Year 12345") << u"Tue Jun 17 08:00:10 12345"_s
<< Qt::TextDate << QDateTime(QDate(12345, 6, 17), QTime(8, 0, 10));
QTest::newRow("text date Year -4712") << QString::fromLatin1("Tue Jan 1 00:01:02 -4712")
QTest::newRow("text date Year -4712") << u"Tue Jan 1 00:01:02 -4712"_s
<< Qt::TextDate << QDateTime(QDate(-4712, 1, 1), QTime(0, 1, 2));
QTest::newRow("text data1") << QString::fromLatin1("Thu Jan 2 12:34 1970")
QTest::newRow("text data1") << u"Thu Jan 2 12:34 1970"_s
<< Qt::TextDate << QDateTime(QDate(1970, 1, 2), QTime(12, 34));
if (goodEpochStart) {
QTest::newRow("text epoch year after time")
<< QString::fromLatin1("Thu Jan 1 00:00:00 1970") << Qt::TextDate
<< u"Thu Jan 1 00:00:00 1970"_s << Qt::TextDate
<< QDate(1970, 1, 1).startOfDay();
QTest::newRow("text epoch spaced")
<< QString::fromLatin1(" Thu Jan 1 00:00:00 1970 ")
<< u" Thu Jan 1 00:00:00 1970 "_s
<< Qt::TextDate << QDate(1970, 1, 1).startOfDay();
QTest::newRow("text epoch time after year")
<< QString::fromLatin1("Thu Jan 1 1970 00:00:00")
<< u"Thu Jan 1 1970 00:00:00"_s
<< Qt::TextDate << QDate(1970, 1, 1).startOfDay();
}
QTest::newRow("text epoch terse")
<< QString::fromLatin1("Thu Jan 1 00 1970") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 00 1970"_s << Qt::TextDate << QDateTime();
QTest::newRow("text epoch stray :00")
<< QString::fromLatin1("Thu Jan 1 00:00:00:00 1970") << Qt::TextDate << QDateTime();
QTest::newRow("text data6") << QString::fromLatin1("Thu Jan 1 00:00:00")
<< u"Thu Jan 1 00:00:00:00 1970"_s << Qt::TextDate << QDateTime();
QTest::newRow("text data6") << u"Thu Jan 1 00:00:00"_s
<< Qt::TextDate << QDateTime();
QTest::newRow("text bad offset") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC+foo")
QTest::newRow("text bad offset") << u"Thu Jan 1 00:12:34 1970 UTC+foo"_s
<< Qt::TextDate << QDateTime();
QTest::newRow("text UTC early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC")
QTest::newRow("text UTC early") << u"Thu Jan 1 00:12:34 1970 UTC"_s
<< Qt::TextDate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
QTest::newRow("text UTC-3 early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC-0300")
QTest::newRow("text UTC-3 early") << u"Thu Jan 1 00:12:34 1970 UTC-0300"_s
<< Qt::TextDate << QDateTime(QDate(1970, 1, 1), QTime(3, 12, 34), UTC);
QTest::newRow("text UTC+3 early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC+0300")
QTest::newRow("text UTC+3 early") << u"Thu Jan 1 00:12:34 1970 UTC+0300"_s
<< Qt::TextDate << QDateTime(QDate(1969, 12, 31), QTime(21, 12, 34), UTC);
QTest::newRow("text UTC+1 early") << QString::fromLatin1("Thu Jan 1 1970 00:12:34 UTC+0100")
QTest::newRow("text UTC+1 early") << u"Thu Jan 1 1970 00:12:34 UTC+0100"_s
<< Qt::TextDate << QDateTime(QDate(1969, 12, 31), QTime(23, 12, 34), UTC);
// We produce use GMT as prefix, so need to parse it:
QTest::newRow("text GMT early")
<< QString::fromLatin1("Thu Jan 1 00:12:34 1970 GMT") << Qt::TextDate
<< u"Thu Jan 1 00:12:34 1970 GMT"_s << Qt::TextDate
<< QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
QTest::newRow("text GMT+3 early")
<< QString::fromLatin1("Thu Jan 1 00:12:34 1970 GMT+0300") << Qt::TextDate
<< u"Thu Jan 1 00:12:34 1970 GMT+0300"_s << Qt::TextDate
<< QDateTime(QDate(1969, 12, 31), QTime(21, 12, 34), UTC);
// ... and we match (only) it case-insensitively:
QTest::newRow("text gmt early")
<< QString::fromLatin1("Thu Jan 1 00:12:34 1970 gmt") << Qt::TextDate
<< u"Thu Jan 1 00:12:34 1970 gmt"_s << Qt::TextDate
<< QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
QTest::newRow("text empty") << QString::fromLatin1("")
QTest::newRow("text empty") << u""_s
<< Qt::TextDate << QDateTime();
QTest::newRow("text too many parts") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC +0100")
QTest::newRow("text too many parts") << u"Thu Jan 1 00:12:34 1970 UTC +0100"_s
<< Qt::TextDate << QDateTime();
QTest::newRow("text invalid month name") << QString::fromLatin1("Thu Jaz 1 1970 00:12:34")
QTest::newRow("text invalid month name") << u"Thu Jaz 1 1970 00:12:34"_s
<< Qt::TextDate << QDateTime();
QTest::newRow("text invalid date") << QString::fromLatin1("Thu Jan 32 1970 00:12:34")
QTest::newRow("text invalid date") << u"Thu Jan 32 1970 00:12:34"_s
<< Qt::TextDate << QDateTime();
QTest::newRow("text pre-5.2 MS-Win format") // Support dropped in 6.2
<< QString::fromLatin1("Thu 1. Jan 00:00:00 1970") << Qt::TextDate << QDateTime();
<< u"Thu 1. Jan 00:00:00 1970"_s << Qt::TextDate << QDateTime();
QTest::newRow("text invalid day")
<< QString::fromLatin1("Thu Jan XX 1970 00:12:34") << Qt::TextDate << QDateTime();
<< u"Thu Jan XX 1970 00:12:34"_s << Qt::TextDate << QDateTime();
QTest::newRow("text misplaced day")
<< QString::fromLatin1("Thu 1 Jan 00:00:00 1970") << Qt::TextDate << QDateTime();
<< u"Thu 1 Jan 00:00:00 1970"_s << Qt::TextDate << QDateTime();
QTest::newRow("text invalid year end")
<< QString::fromLatin1("Thu Jan 1 00:00:00 19X0") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 00:00:00 19X0"_s << Qt::TextDate << QDateTime();
QTest::newRow("text invalid year early")
<< QString::fromLatin1("Thu Jan 1 19X0 00:00:00") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 19X0 00:00:00"_s << Qt::TextDate << QDateTime();
QTest::newRow("text invalid hour")
<< QString::fromLatin1("Thu Jan 1 1970 0X:00:00") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 1970 0X:00:00"_s << Qt::TextDate << QDateTime();
QTest::newRow("text invalid minute")
<< QString::fromLatin1("Thu Jan 1 1970 00:0X:00") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 1970 00:0X:00"_s << Qt::TextDate << QDateTime();
QTest::newRow("text invalid second")
<< QString::fromLatin1("Thu Jan 1 1970 00:00:0X") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 1970 00:00:0X"_s << Qt::TextDate << QDateTime();
QTest::newRow("text non-UTC offset")
<< QString::fromLatin1("Thu Jan 1 1970 00:00:00 DMT") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 1970 00:00:00 DMT"_s << Qt::TextDate << QDateTime();
QTest::newRow("text bad UTC offset")
<< QString::fromLatin1("Thu Jan 1 1970 00:00:00 UTCx0200") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 1970 00:00:00 UTCx0200"_s << Qt::TextDate << QDateTime();
QTest::newRow("text bad UTC hour")
<< QString::fromLatin1("Thu Jan 1 1970 00:00:00 UTC+0X00") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 1970 00:00:00 UTC+0X00"_s << Qt::TextDate << QDateTime();
QTest::newRow("text bad UTC minute")
<< QString::fromLatin1("Thu Jan 1 1970 00:00:00 UTC+000X") << Qt::TextDate << QDateTime();
<< u"Thu Jan 1 1970 00:00:00 UTC+000X"_s << Qt::TextDate << QDateTime();
QTest::newRow("text second fraction")
<< QString::fromLatin1("Mon May 6 2013 01:02:03.456")
<< u"Mon May 6 2013 01:02:03.456"_s
<< Qt::TextDate << QDateTime(QDate(2013, 5, 6), QTime(1, 2, 3, 456));
QTest::newRow("text max milli")
<< QString::fromLatin1("Mon May 6 2013 01:02:03.999499999")
<< u"Mon May 6 2013 01:02:03.999499999"_s
<< Qt::TextDate << QDateTime(QDate(2013, 5, 6), QTime(1, 2, 3, 999));
QTest::newRow("text milli wrap")
<< QString::fromLatin1("Mon May 6 2013 01:02:03.9995")
<< u"Mon May 6 2013 01:02:03.9995"_s
<< Qt::TextDate << QDateTime(QDate(2013, 5, 6), QTime(1, 2, 4));
QTest::newRow("text last milli") // Special case, don't round up to invalid:
<< QString::fromLatin1("Mon May 6 2013 23:59:59.9999999999")
<< u"Mon May 6 2013 23:59:59.9999999999"_s
<< Qt::TextDate << QDateTime(QDate(2013, 5, 6), QTime(23, 59, 59, 999));
QTest::newRow("text Sunday lunch")
<< QStringLiteral("Sun Dec 1 13:02:00 1974") << Qt::TextDate
<< u"Sun Dec 1 13:02:00 1974"_s << Qt::TextDate
<< QDateTime(QDate(1974, 12, 1), QTime(13, 2));
// Test Qt::ISODate format.
QTest::newRow("trailing space") // QTBUG-80445
<< QString("2000-01-02 03:04:05.678 ") << Qt::ISODate << QDateTime();
<< u"2000-01-02 03:04:05.678 "_s << Qt::ISODate << QDateTime();
// Invalid spaces (but keeping field widths correct):
QTest::newRow("space before millis")
<< QString("2000-01-02 03:04:05. 678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 03:04:05. 678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space after seconds")
<< QString("2000-01-02 03:04:5 .678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 03:04:5 .678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space before seconds")
<< QString("2000-01-02 03:04: 5.678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 03:04: 5.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space after minutes")
<< QString("2000-01-02 03:4 :05.678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 03:4 :05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space before minutes")
<< QString("2000-01-02 03: 4:05.678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 03: 4:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space after hour")
<< QString("2000-01-02 3 :04:05.678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 3 :04:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space before hour")
<< QString("2000-01-02 3:04:05.678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 3:04:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space after day")
<< QString("2000-01-2 03:04:05.678") << Qt::ISODate << QDateTime();
<< u"2000-01-2 03:04:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space before day")
<< QString("2000-01- 2 03:04:05.678") << Qt::ISODate << QDateTime();
<< u"2000-01- 2 03:04:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space after month")
<< QString("2000-1 -02 03:04:05.678") << Qt::ISODate << QDateTime();
<< u"2000-1 -02 03:04:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space before month")
<< QString("2000- 1-02 03:04:05.678") << Qt::ISODate << QDateTime();
<< u"2000- 1-02 03:04:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("space after year")
<< QString("200 -01-02 03:04:05.678") << Qt::ISODate << QDateTime();
<< u"200 -01-02 03:04:05.678"_s << Qt::ISODate << QDateTime();
// Spaces as separators:
QTest::newRow("sec-milli space")
<< QString("2000-01-02 03:04:05 678") << Qt::ISODate
<< u"2000-01-02 03:04:05 678"_s << Qt::ISODate
<< QDateTime();
QTest::newRow("min-sec space")
<< QString("2000-01-02 03:04 05.678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 03:04 05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("hour-min space")
<< QString("2000-01-02 03 04:05.678") << Qt::ISODate << QDateTime();
<< u"2000-01-02 03 04:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("mon-day space")
<< QString("2000-01 02 03:04:05.678") << Qt::ISODate << QDateTime();
<< u"2000-01 02 03:04:05.678"_s << Qt::ISODate << QDateTime();
QTest::newRow("year-mon space")
<< QString("2000 01-02 03:04:05.678") << Qt::ISODate << QDateTime();
<< u"2000 01-02 03:04:05.678"_s << Qt::ISODate << QDateTime();
// Normal usage:
QTest::newRow("ISO +01:00") << QString::fromLatin1("1987-02-13T13:24:51+01:00")
QTest::newRow("ISO +01:00") << u"1987-02-13T13:24:51+01:00"_s
<< Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC);
QTest::newRow("ISO +00:01") << QString::fromLatin1("1987-02-13T13:24:51+00:01")
QTest::newRow("ISO +00:01") << u"1987-02-13T13:24:51+00:01"_s
<< Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(13, 23, 51), UTC);
QTest::newRow("ISO -01:00") << QString::fromLatin1("1987-02-13T13:24:51-01:00")
QTest::newRow("ISO -01:00") << u"1987-02-13T13:24:51-01:00"_s
<< Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), UTC);
QTest::newRow("ISO -00:01") << QString::fromLatin1("1987-02-13T13:24:51-00:01")
QTest::newRow("ISO -00:01") << u"1987-02-13T13:24:51-00:01"_s
<< Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(13, 25, 51), UTC);
QTest::newRow("ISO +0000") << QString::fromLatin1("1970-01-01T00:12:34+0000")
QTest::newRow("ISO +0000") << u"1970-01-01T00:12:34+0000"_s
<< Qt::ISODate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
QTest::newRow("ISO +00:00") << QString::fromLatin1("1970-01-01T00:12:34+00:00")
QTest::newRow("ISO +00:00") << u"1970-01-01T00:12:34+00:00"_s
<< Qt::ISODate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
QTest::newRow("ISO -03") << QString::fromLatin1("2014-12-15T12:37:09-03")
QTest::newRow("ISO -03") << u"2014-12-15T12:37:09-03"_s
<< Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9), UTC);
QTest::newRow("ISO zzz-03") << QString::fromLatin1("2014-12-15T12:37:09.745-03")
QTest::newRow("ISO zzz-03") << u"2014-12-15T12:37:09.745-03"_s
<< Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9, 745), UTC);
QTest::newRow("ISO -3") << QString::fromLatin1("2014-12-15T12:37:09-3")
QTest::newRow("ISO -3") << u"2014-12-15T12:37:09-3"_s
<< Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9), UTC);
QTest::newRow("ISO zzz-3") << QString::fromLatin1("2014-12-15T12:37:09.745-3")
QTest::newRow("ISO zzz-3") << u"2014-12-15T12:37:09.745-3"_s
<< Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9, 745), UTC);
QTest::newRow("ISO lower-case") << QString::fromLatin1("2005-06-28T07:57:30.002z")
QTest::newRow("ISO lower-case") << u"2005-06-28T07:57:30.002z"_s
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), UTC);
// No time specified - defaults to Qt::LocalTime.
QTest::newRow("ISO data3") << QString::fromLatin1("2002-10-01")
QTest::newRow("ISO data3") << u"2002-10-01"_s
<< Qt::ISODate << QDate(2002, 10, 1).startOfDay();
// Excess digits in milliseconds, round correctly:
QTest::newRow("ISO") << QString::fromLatin1("2005-06-28T07:57:30.0010000000Z")
QTest::newRow("ISO") << u"2005-06-28T07:57:30.0010000000Z"_s
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), UTC);
QTest::newRow("ISO rounding") << QString::fromLatin1("2005-06-28T07:57:30.0015Z")
QTest::newRow("ISO rounding") << u"2005-06-28T07:57:30.0015Z"_s
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), UTC);
// ... and accept comma as separator:
QTest::newRow("ISO with comma 1") << QString::fromLatin1("2005-06-28T07:57:30,0040000000Z")
QTest::newRow("ISO with comma 1") << u"2005-06-28T07:57:30,0040000000Z"_s
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 4), UTC);
QTest::newRow("ISO with comma 2") << QString::fromLatin1("2005-06-28T07:57:30,0015Z")
QTest::newRow("ISO with comma 2") << u"2005-06-28T07:57:30,0015Z"_s
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), UTC);
QTest::newRow("ISO with comma 3") << QString::fromLatin1("2005-06-28T07:57:30,0014Z")
QTest::newRow("ISO with comma 3") << u"2005-06-28T07:57:30,0014Z"_s
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), UTC);
QTest::newRow("ISO with comma 4") << QString::fromLatin1("2005-06-28T07:57:30,1Z")
QTest::newRow("ISO with comma 4") << u"2005-06-28T07:57:30,1Z"_s
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 100), UTC);
QTest::newRow("ISO with comma 5") << QString::fromLatin1("2005-06-28T07:57:30,11")
QTest::newRow("ISO with comma 5") << u"2005-06-28T07:57:30,11"_s
<< Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 110));
// 24:00:00 Should be next day according to ISO 8601 section 4.2.3.
QTest::newRow("ISO 24:00") << QString::fromLatin1("2012-06-04T24:00:00")
QTest::newRow("ISO 24:00") << u"2012-06-04T24:00:00"_s
<< Qt::ISODate << QDate(2012, 6, 5).startOfDay();
#if QT_CONFIG(timezone)
const QByteArray sysId = QTimeZone::systemTimeZoneId();
@ -2954,198 +2954,198 @@ void tst_QDateTime::fromStringDateFormat_data()
|| sysId == "America/Argentina/Buenos_Aires"
|| sysId == "America/Argentina/Tucuman" || sysId == "Brazil/East";
QTest::newRow("ISO 24:00 in DST") // Midnight spring forward in some of South America.
<< QString::fromLatin1("2008-10-18T24:00") << Qt::ISODate
<< u"2008-10-18T24:00"_s << Qt::ISODate
<< QDateTime(QDate(2008, 10, 19), QTime(midnightSkip ? 1 : 0, 0));
#endif
QTest::newRow("ISO 24:00 end of month")
<< QString::fromLatin1("2012-06-30T24:00:00")
<< u"2012-06-30T24:00:00"_s
<< Qt::ISODate << QDate(2012, 7, 1).startOfDay();
QTest::newRow("ISO 24:00 end of year")
<< QString::fromLatin1("2012-12-31T24:00:00")
<< u"2012-12-31T24:00:00"_s
<< Qt::ISODate << QDate(2013, 1, 1).startOfDay();
QTest::newRow("ISO 24:00, fract ms")
<< QString::fromLatin1("2012-01-01T24:00:00.000")
<< u"2012-01-01T24:00:00.000"_s
<< Qt::ISODate << QDate(2012, 1, 2).startOfDay();
QTest::newRow("ISO 24:00 end of year, fract ms")
<< QString::fromLatin1("2012-12-31T24:00:00.000")
<< u"2012-12-31T24:00:00.000"_s
<< Qt::ISODate << QDate(2013, 1, 1).startOfDay();
// Test fractional seconds.
QTest::newRow("ISO .0 of a second (period)")
<< QString::fromLatin1("2012-01-01T08:00:00.0")
<< u"2012-01-01T08:00:00.0"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0));
QTest::newRow("ISO .00 of a second (period)") << QString::fromLatin1("2012-01-01T08:00:00.00")
QTest::newRow("ISO .00 of a second (period)") << u"2012-01-01T08:00:00.00"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0));
QTest::newRow("ISO .000 of a second (period)") << QString::fromLatin1("2012-01-01T08:00:00.000")
QTest::newRow("ISO .000 of a second (period)") << u"2012-01-01T08:00:00.000"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0));
QTest::newRow("ISO .1 of a second (comma)") << QString::fromLatin1("2012-01-01T08:00:00,1")
QTest::newRow("ISO .1 of a second (comma)") << u"2012-01-01T08:00:00,1"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 100));
QTest::newRow("ISO .99 of a second (comma)") << QString::fromLatin1("2012-01-01T08:00:00,99")
QTest::newRow("ISO .99 of a second (comma)") << u"2012-01-01T08:00:00,99"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 990));
QTest::newRow("ISO .998 of a second (comma)") << QString::fromLatin1("2012-01-01T08:00:00,998")
QTest::newRow("ISO .998 of a second (comma)") << u"2012-01-01T08:00:00,998"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 998));
QTest::newRow("ISO .999 of a second (comma)") << QString::fromLatin1("2012-01-01T08:00:00,999")
QTest::newRow("ISO .999 of a second (comma)") << u"2012-01-01T08:00:00,999"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 999));
QTest::newRow("ISO .3335 of a second (comma)") << QString::fromLatin1("2012-01-01T08:00:00,3335")
QTest::newRow("ISO .3335 of a second (comma)") << u"2012-01-01T08:00:00,3335"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 334));
QTest::newRow("ISO .333333 of a second (comma)") << QString::fromLatin1("2012-01-01T08:00:00,333333")
QTest::newRow("ISO .333333 of a second (comma)") << u"2012-01-01T08:00:00,333333"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 0, 333));
QTest::newRow("ISO .00009 of a second (period)") << QString::fromLatin1("2012-01-01T08:00:00.00009")
QTest::newRow("ISO .00009 of a second (period)") << u"2012-01-01T08:00:00.00009"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0));
QTest::newRow("ISO second fraction") << QString::fromLatin1("2013-05-06T01:02:03.456")
QTest::newRow("ISO second fraction") << u"2013-05-06T01:02:03.456"_s
<< Qt::ISODate << QDateTime(QDate(2013, 5, 6), QTime(1, 2, 3, 456));
QTest::newRow("ISO max milli")
<< QString::fromLatin1("2013-05-06T01:02:03.999499999")
<< u"2013-05-06T01:02:03.999499999"_s
<< Qt::ISODate << QDateTime(QDate(2013, 5, 6), QTime(1, 2, 3, 999));
QTest::newRow("ISO milli wrap")
<< QString::fromLatin1("2013-05-06T01:02:03.9995")
<< u"2013-05-06T01:02:03.9995"_s
<< Qt::ISODate << QDateTime(QDate(2013, 5, 6), QTime(1, 2, 4));
QTest::newRow("ISO last milli") // Does round up and overflow into new day:
<< QString::fromLatin1("2013-05-06T23:59:59.9999999999")
<< u"2013-05-06T23:59:59.9999999999"_s
<< Qt::ISODate << QDate(2013, 5, 7).startOfDay();
QTest::newRow("ISO no fraction specified")
<< QString::fromLatin1("2012-01-01T08:00:00.") << Qt::ISODate << QDateTime();
<< u"2012-01-01T08:00:00."_s << Qt::ISODate << QDateTime();
// Test invalid characters (should ignore invalid characters at end of string).
QTest::newRow("ISO invalid character at end") << QString::fromLatin1("2012-01-01T08:00:00!")
QTest::newRow("ISO invalid character at end") << u"2012-01-01T08:00:00!"_s
<< Qt::ISODate << QDateTime();
QTest::newRow("ISO invalid character at front") << QString::fromLatin1("!2012-01-01T08:00:00")
QTest::newRow("ISO invalid character at front") << u"!2012-01-01T08:00:00"_s
<< Qt::ISODate << QDateTime();
QTest::newRow("ISO invalid character both ends") << QString::fromLatin1("!2012-01-01T08:00:00!")
QTest::newRow("ISO invalid character both ends") << u"!2012-01-01T08:00:00!"_s
<< Qt::ISODate << QDateTime();
QTest::newRow("ISO invalid character at front, 2 at back") << QString::fromLatin1("!2012-01-01T08:00:00..")
QTest::newRow("ISO invalid character at front, 2 at back") << u"!2012-01-01T08:00:00.."_s
<< Qt::ISODate << QDateTime();
QTest::newRow("ISO invalid character 2 at front") << QString::fromLatin1("!!2012-01-01T08:00:00")
QTest::newRow("ISO invalid character 2 at front") << u"!!2012-01-01T08:00:00"_s
<< Qt::ISODate << QDateTime();
// Test fractional minutes.
QTest::newRow("ISO .0 of a minute (period)") << QString::fromLatin1("2012-01-01T08:00.0")
QTest::newRow("ISO .0 of a minute (period)") << u"2012-01-01T08:00.0"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0));
QTest::newRow("ISO .8 of a minute (period)") << QString::fromLatin1("2012-01-01T08:00.8")
QTest::newRow("ISO .8 of a minute (period)") << u"2012-01-01T08:00.8"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 48));
QTest::newRow("ISO .99999 of a minute (period)") << QString::fromLatin1("2012-01-01T08:00.99999")
QTest::newRow("ISO .99999 of a minute (period)") << u"2012-01-01T08:00.99999"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 59, 999));
QTest::newRow("ISO .0 of a minute (comma)") << QString::fromLatin1("2012-01-01T08:00,0")
QTest::newRow("ISO .0 of a minute (comma)") << u"2012-01-01T08:00,0"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0));
QTest::newRow("ISO .8 of a minute (comma)") << QString::fromLatin1("2012-01-01T08:00,8")
QTest::newRow("ISO .8 of a minute (comma)") << u"2012-01-01T08:00,8"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 48));
QTest::newRow("ISO .99999 of a minute (comma)") << QString::fromLatin1("2012-01-01T08:00,99999")
QTest::newRow("ISO .99999 of a minute (comma)") << u"2012-01-01T08:00,99999"_s
<< Qt::ISODate << QDateTime(QDate(2012, 1, 1), QTime(8, 0, 59, 999));
QTest::newRow("ISO empty") << QString::fromLatin1("") << Qt::ISODate << QDateTime();
QTest::newRow("ISO short") << QString::fromLatin1("2017-07-01T") << Qt::ISODate << QDateTime();
QTest::newRow("ISO empty") << u""_s << Qt::ISODate << QDateTime();
QTest::newRow("ISO short") << u"2017-07-01T"_s << Qt::ISODate << QDateTime();
QTest::newRow("ISO zoned date")
<< QString::fromLatin1("2017-07-01Z") << Qt::ISODate << QDateTime();
<< u"2017-07-01Z"_s << Qt::ISODate << QDateTime();
QTest::newRow("ISO zoned empty time")
<< QString::fromLatin1("2017-07-01TZ") << Qt::ISODate << QDateTime();
<< u"2017-07-01TZ"_s << Qt::ISODate << QDateTime();
QTest::newRow("ISO mis-punctuated")
<< QString::fromLatin1("2018/01/30 ") << Qt::ISODate << QDateTime();
<< u"2018/01/30 "_s << Qt::ISODate << QDateTime();
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822 +0100") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 +0100") << u"13 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC);
QTest::newRow("RFC 2822 after space +0100")
<< QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
<< u" 13 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC);
QTest::newRow("RFC 2822 with day +0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 with day +0100") << u"Fri, 13 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC);
QTest::newRow("RFC 2822 with day after space +0100")
<< QString::fromLatin1(" Fri, 13 Feb 1987 13:24:51 +0100")
<< u" Fri, 13 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC);
QTest::newRow("RFC 2822 -0100") << QString::fromLatin1("13 Feb 1987 13:24:51 -0100")
QTest::newRow("RFC 2822 -0100") << u"13 Feb 1987 13:24:51 -0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), UTC);
QTest::newRow("RFC 2822 with day -0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 -0100")
QTest::newRow("RFC 2822 with day -0100") << u"Fri, 13 Feb 1987 13:24:51 -0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), UTC);
QTest::newRow("RFC 2822 +0000") << QString::fromLatin1("01 Jan 1970 00:12:34 +0000")
QTest::newRow("RFC 2822 +0000") << u"01 Jan 1970 00:12:34 +0000"_s
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
QTest::newRow("RFC 2822 with day +0000") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
QTest::newRow("RFC 2822 with day +0000") << u"Thu, 01 Jan 1970 00:12:34 +0000"_s
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
QTest::newRow("RFC 2822 missing space before +0100")
<< QString::fromLatin1("Thu, 01 Jan 1970 00:12:34+0100") << Qt::RFC2822Date << QDateTime();
<< u"Thu, 01 Jan 1970 00:12:34+0100"_s << Qt::RFC2822Date << QDateTime();
// No timezone assume UTC
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
QTest::newRow("RFC 2822 no timezone") << u"01 Jan 1970 00:12:34"_s
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
// No time specified
QTest::newRow("RFC 2822 date only") << QString::fromLatin1("01 Nov 2002")
QTest::newRow("RFC 2822 date only") << u"01 Nov 2002"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 with day date only") << QString::fromLatin1("Fri, 01 Nov 2002")
QTest::newRow("RFC 2822 with day date only") << u"Fri, 01 Nov 2002"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 malformed time (truncated)")
<< QString::fromLatin1("01 Nov 2002 0:") << Qt::RFC2822Date << QDateTime();
<< u"01 Nov 2002 0:"_s << Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 malformed time (hour)")
<< QString::fromLatin1("01 Nov 2002 7:35:21") << Qt::RFC2822Date << QDateTime();
<< u"01 Nov 2002 7:35:21"_s << Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 malformed time (minute)")
<< QString::fromLatin1("01 Nov 2002 07:5:21") << Qt::RFC2822Date << QDateTime();
<< u"01 Nov 2002 07:5:21"_s << Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 malformed time (second)")
<< QString::fromLatin1("01 Nov 2002 07:35:1") << Qt::RFC2822Date << QDateTime();
<< u"01 Nov 2002 07:35:1"_s << Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 malformed time (fraction-second)")
<< QString::fromLatin1("01 Nov 2002 07:35:15.200") << Qt::RFC2822Date << QDateTime();
<< u"01 Nov 2002 07:35:15.200"_s << Qt::RFC2822Date << QDateTime();
// Test invalid month, day, year
QTest::newRow("RFC 2822 invalid month name") << QString::fromLatin1("13 Fev 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid month name") << u"13 Fev 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 invalid day") << QString::fromLatin1("36 Fev 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid day") << u"36 Fev 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid year") << u"13 Fev 0000 13:24:51 +0100"_s
<< Qt::RFC2822Date << QDateTime();
// Test invalid characters.
QTest::newRow("RFC 2822 invalid character at end")
<< QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
<< u"01 Jan 2012 08:00:00 +0100!"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 invalid character at front")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100")
<< u"!01 Jan 2012 08:00:00 +0100"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 invalid character both ends")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!")
<< u"!01 Jan 2012 08:00:00 +0100!"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 invalid character at front, 2 at back")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..")
<< u"!01 Jan 2012 08:00:00 +0100.."_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 invalid character 2 at front")
<< QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100")
<< u"!!01 Jan 2012 08:00:00 +0100"_s
<< Qt::RFC2822Date << QDateTime();
// The common date text used by the "invalid character" tests, just to be
// sure *it's* not what's invalid:
QTest::newRow("RFC 2822 (not invalid)")
<< QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
<< u"01 Jan 2012 08:00:00 +0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0), UTC);
// Test Qt::RFC2822Date format (RFC 850 and 1036, permissive).
QTest::newRow("RFC 850 and 1036 +0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100")
QTest::newRow("RFC 850 and 1036 +0100") << u"Fri Feb 13 13:24:51 1987 +0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC);
QTest::newRow("RFC 1036 after space +0100")
<< QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
<< u" Fri Feb 13 13:24:51 1987 +0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC);
QTest::newRow("RFC 850 and 1036 -0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 -0100")
QTest::newRow("RFC 850 and 1036 -0100") << u"Fri Feb 13 13:24:51 1987 -0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), UTC);
QTest::newRow("RFC 850 and 1036 +0000") << QString::fromLatin1("Thu Jan 01 00:12:34 1970 +0000")
QTest::newRow("RFC 850 and 1036 +0000") << u"Thu Jan 01 00:12:34 1970 +0000"_s
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
// No timezone assume UTC
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
QTest::newRow("RFC 850 and 1036 no timezone") << u"Thu Jan 01 00:12:34 1970"_s
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC);
// No time specified
QTest::newRow("RFC 850 and 1036 date only")
<< QString::fromLatin1("Fri Nov 01 2002")
<< u"Fri Nov 01 2002"_s
<< Qt::RFC2822Date << QDateTime();
// Test invalid characters.
QTest::newRow("RFC 850 and 1036 invalid character at end")
<< QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
<< u"Sun Jan 01 08:00:00 2012 +0100!"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 850 and 1036 invalid character at front")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100")
<< u"!Sun Jan 01 08:00:00 2012 +0100"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 850 and 1036 invalid character both ends")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!")
<< u"!Sun Jan 01 08:00:00 2012 +0100!"_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..")
<< u"!Sun Jan 01 08:00:00 2012 +0100.."_s
<< Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 850 and 1036 invalid character 2 at front")
<< QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0100")
<< u"!!Sun Jan 01 08:00:00 2012 +0100"_s
<< Qt::RFC2822Date << QDateTime();
// Again, check the text in the "invalid character" tests isn't the source of invalidity:
QTest::newRow("RFC 850 and 1036 (not invalid)")
<< QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100")
<< u"Sun Jan 01 08:00:00 2012 +0100"_s
<< Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0), UTC);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC empty") << u""_s << Qt::RFC2822Date << QDateTime();
}
void tst_QDateTime::fromStringDateFormat()
@ -3383,8 +3383,8 @@ void tst_QDateTime::fromStringStringFormat_data()
// test unicode
QTest::newRow("unicode handling")
<< QString(u8"2005🤣06🤣28T07🤣57🤣30.001Z")
<< QString(u8"yyyy🤣MM🤣ddThh🤣mm🤣ss.zt") << 1900
<< u"2005🤣06🤣28T07🤣57🤣30.001Z"_s
<< u"yyyy🤣MM🤣ddThh🤣mm🤣ss.zt"_s << 1900
<< QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), UTC);
// Two tests derived from malformed ASN.1 strings (QTBUG-84349):
@ -3774,12 +3774,12 @@ void tst_QDateTime::zoneAtTime()
void tst_QDateTime::timeZoneAbbreviation()
{
QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0), QTimeZone::fromSecondsAheadOfUtc(60 * 60));
QCOMPARE(dt1.timeZoneAbbreviation(), QString("UTC+01:00"));
QCOMPARE(dt1.timeZoneAbbreviation(), u"UTC+01:00"_s);
QDateTime dt2(QDate(2013, 1, 1), QTime(1, 0), QTimeZone::fromSecondsAheadOfUtc(-60 * 60));
QCOMPARE(dt2.timeZoneAbbreviation(), QString("UTC-01:00"));
QCOMPARE(dt2.timeZoneAbbreviation(), u"UTC-01:00"_s);
QDateTime dt3(QDate(2013, 1, 1), QTime(0, 0), UTC);
QCOMPARE(dt3.timeZoneAbbreviation(), QString("UTC"));
QCOMPARE(dt3.timeZoneAbbreviation(), u"UTC"_s);
// LocalTime should vary
if (zoneIsCET) {
@ -3846,16 +3846,16 @@ void tst_QDateTime::getDate()
void tst_QDateTime::fewDigitsInYear() const
{
const QDateTime three(QDate(300, 10, 11).startOfDay());
QCOMPARE(three.toString(QLatin1String("yyyy-MM-dd")), QString::fromLatin1("0300-10-11"));
QCOMPARE(three.toString(u"yyyy-MM-dd"), "0300-10-11"_L1);
const QDateTime two(QDate(20, 10, 11).startOfDay());
QCOMPARE(two.toString(QLatin1String("yyyy-MM-dd")), QString::fromLatin1("0020-10-11"));
QCOMPARE(two.toString(u"yyyy-MM-dd"), "0020-10-11"_L1);
const QDateTime yyTwo(QDate(30, 10, 11).startOfDay());
QCOMPARE(yyTwo.toString(QLatin1String("yy-MM-dd")), QString::fromLatin1("30-10-11"));
QCOMPARE(yyTwo.toString(u"yy-MM-dd"), "30-10-11"_L1);
const QDateTime yyOne(QDate(4, 10, 11).startOfDay());
QCOMPARE(yyOne.toString(QLatin1String("yy-MM-dd")), QString::fromLatin1("04-10-11"));
QCOMPARE(yyOne.toString(u"yy-MM-dd"), "04-10-11"_L1);
}
void tst_QDateTime::printNegativeYear() const
@ -3863,19 +3863,19 @@ void tst_QDateTime::printNegativeYear() const
{
QDateTime date(QDate(-20, 10, 11).startOfDay());
QVERIFY(date.isValid());
QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0020"));
QCOMPARE(date.toString(u"yyyy"), "-0020"_L1);
}
{
QDateTime date(QDate(-3, 10, 11).startOfDay());
QVERIFY(date.isValid());
QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0003"));
QCOMPARE(date.toString(u"yyyy"), "-0003"_L1);
}
{
QDateTime date(QDate(-400, 10, 11).startOfDay());
QVERIFY(date.isValid());
QCOMPARE(date.toString(QLatin1String("yyyy")), QString::fromLatin1("-0400"));
QCOMPARE(date.toString(u"yyyy"), "-0400"_L1);
}
}

View File

@ -14,6 +14,11 @@ endif()
qt_internal_add_test(tst_qdatetimeparser
SOURCES
tst_qdatetimeparser.cpp
DEFINES
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_FOREACH
QT_NO_KEYWORDS
LIBRARIES
Qt::CorePrivate
)

View File

@ -15,6 +15,8 @@ qt_internal_add_test(tst_qtime
SOURCES
tst_qtime.cpp
DEFINES
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_FOREACH
QT_NO_KEYWORDS
LIBRARIES

View File

@ -9,6 +9,8 @@
# include <locale.h>
#endif
using namespace Qt::StringLiterals;
class tst_QTime : public QObject
{
Q_OBJECT
@ -363,8 +365,8 @@ void tst_QTime::ordering_data()
QTest::addColumn<Qt::strong_ordering>("expectedOrdering");
auto generateRow = [](QTime t1, QTime t2, Qt::strong_ordering ordering) {
const QByteArray t1Str = t1.toString("hh:mm:ss.zz").toLatin1();
const QByteArray t2Str = t2.toString("hh:mm:ss.zz").toLatin1();
const QByteArray t1Str = t1.toString(u"hh:mm:ss.zz").toLatin1();
const QByteArray t2Str = t2.toString(u"hh:mm:ss.zz").toLatin1();
QTest::addRow("%s_vs_%s", t1Str.constData(), t2Str.constData()) << t1 << t2 << ordering;
};
@ -396,34 +398,34 @@ void tst_QTime::fromStringFormat_data()
QTest::addColumn<QString>("format");
QTest::addColumn<QTime>("expected");
QTest::newRow("data0") << QString("1010") << QString("mmm") << QTime(0, 10, 0);
QTest::newRow("data1") << QString("00") << QString("hm") << invalidTime();
QTest::newRow("data2") << QString("10am") << QString("hap") << QTime(10, 0, 0);
QTest::newRow("data3") << QString("10pm") << QString("hap") << QTime(22, 0, 0);
QTest::newRow("data4") << QString("10pmam") << QString("hapap") << invalidTime();
QTest::newRow("data5") << QString("1070") << QString("hhm") << invalidTime();
QTest::newRow("data6") << QString("1011") << QString("hh") << invalidTime();
QTest::newRow("data7") << QString("25") << QString("hh") << invalidTime();
QTest::newRow("data8") << QString("22pm") << QString("Hap") << QTime(22, 0, 0);
QTest::newRow("data9") << QString("2221") << QString("hhhh") << invalidTime();
QTest::newRow("data0") << u"1010"_s << u"mmm"_s << QTime(0, 10, 0);
QTest::newRow("data1") << u"00"_s << u"hm"_s << invalidTime();
QTest::newRow("data2") << u"10am"_s << u"hap"_s << QTime(10, 0, 0);
QTest::newRow("data3") << u"10pm"_s << u"hap"_s << QTime(22, 0, 0);
QTest::newRow("data4") << u"10pmam"_s << u"hapap"_s << invalidTime();
QTest::newRow("data5") << u"1070"_s << u"hhm"_s << invalidTime();
QTest::newRow("data6") << u"1011"_s << u"hh"_s << invalidTime();
QTest::newRow("data7") << u"25"_s << u"hh"_s << invalidTime();
QTest::newRow("data8") << u"22pm"_s << u"Hap"_s << QTime(22, 0, 0);
QTest::newRow("data9") << u"2221"_s << u"hhhh"_s << invalidTime();
// Parsing of am/pm indicators is case-insensitive
QTest::newRow("pm-upper") << QString("02:23PM") << QString("hh:mmAp") << QTime(14, 23);
QTest::newRow("pm-lower") << QString("02:23pm") << QString("hh:mmaP") << QTime(14, 23);
QTest::newRow("pm-as-upper") << QString("02:23Pm") << QString("hh:mmAP") << QTime(14, 23);
QTest::newRow("pm-as-lower") << QString("02:23pM") << QString("hh:mmap") << QTime(14, 23);
QTest::newRow("pm-upper") << u"02:23PM"_s << u"hh:mmAp"_s << QTime(14, 23);
QTest::newRow("pm-lower") << u"02:23pm"_s << u"hh:mmaP"_s << QTime(14, 23);
QTest::newRow("pm-as-upper") << u"02:23Pm"_s << u"hh:mmAP"_s << QTime(14, 23);
QTest::newRow("pm-as-lower") << u"02:23pM"_s << u"hh:mmap"_s << QTime(14, 23);
// Millisecond parsing must interpolate 0s only at the end and notice them at the start.
QTest::newRow("short-msecs-lt100")
<< QString("10:12:34:045") << QString("hh:m:ss:z") << QTime(10, 12, 34, 45);
<< u"10:12:34:045"_s << u"hh:m:ss:z"_s << 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);
<< u"10:12:34:45"_s << u"hh:m:ss:z"_s << QTime(10, 12, 34, 450);
QTest::newRow("late")
<< QString("23:59:59.999") << QString("hh:mm:ss.z") << QTime(23, 59, 59, 999);
<< u"23:59:59.999"_s << u"hh:mm:ss.z"_s << QTime(23, 59, 59, 999);
// Test unicode handling.
QTest::newRow("emoji in format string 1")
<< QString("12👍31:25.05") << QString("hh👍mm:ss.z") << QTime(12, 31, 25, 50);
<< u"12👍31:25.05"_s << u"hh👍mm:ss.z"_s << QTime(12, 31, 25, 50);
QTest::newRow("emoji in format string 2")
<< QString("💖12👍31🌈25😺05🚀") << QString("💖hh👍mm🌈ss😺z🚀") << QTime(12, 31, 25, 50);
<< u"💖12👍31🌈25😺05🚀"_s << u"💖hh👍mm🌈ss😺z🚀"_s << QTime(12, 31, 25, 50);
}
void tst_QTime::fromStringFormat()
@ -443,139 +445,139 @@ void tst_QTime::fromStringDateFormat_data()
QTest::addColumn<Qt::DateFormat>("format");
QTest::addColumn<QTime>("expected");
QTest::newRow("TextDate - zero") << QString("00:00:00") << Qt::TextDate << QTime(0, 0);
QTest::newRow("TextDate - zero") << u"00:00:00"_s << Qt::TextDate << QTime(0, 0);
QTest::newRow("TextDate - ordinary")
<< QString("10:12:34") << Qt::TextDate << QTime(10, 12, 34);
<< u"10:12:34"_s << Qt::TextDate << QTime(10, 12, 34);
QTest::newRow("TextDate - milli-max")
<< QString("19:03:54.998601") << Qt::TextDate << QTime(19, 3, 54, 999);
<< u"19:03:54.998601"_s << Qt::TextDate << QTime(19, 3, 54, 999);
QTest::newRow("TextDate - milli-wrap")
<< QString("19:03:54.999601") << Qt::TextDate << QTime(19, 3, 55);
<< u"19:03:54.999601"_s << Qt::TextDate << QTime(19, 3, 55);
QTest::newRow("TextDate - no-secs")
<< QString("10:12") << Qt::TextDate << QTime(10, 12);
<< u"10:12"_s << Qt::TextDate << QTime(10, 12);
QTest::newRow("TextDate - midnight-nowrap")
<< QString("23:59:59.9999") << Qt::TextDate << QTime(23, 59, 59, 999);
QTest::newRow("TextDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::TextDate << invalidTime();
QTest::newRow("TextDate - invalid, minute fraction") << QString::fromLatin1("23:00.123456") << Qt::TextDate << invalidTime();
QTest::newRow("TextDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::TextDate << invalidTime();
QTest::newRow("TextDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::TextDate
<< u"23:59:59.9999"_s << Qt::TextDate << QTime(23, 59, 59, 999);
QTest::newRow("TextDate - invalid, minutes") << u"23:XX:00"_s << Qt::TextDate << invalidTime();
QTest::newRow("TextDate - invalid, minute fraction") << u"23:00.123456"_s << Qt::TextDate << invalidTime();
QTest::newRow("TextDate - invalid, seconds") << u"23:00:XX"_s << Qt::TextDate << invalidTime();
QTest::newRow("TextDate - invalid, milliseconds") << u"23:01:01:XXXX"_s << Qt::TextDate
<< invalidTime();
QTest::newRow("TextDate - midnight 24") << QString("24:00:00") << Qt::TextDate << QTime();
QTest::newRow("TextDate - midnight 24") << u"24:00:00"_s << Qt::TextDate << QTime();
QTest::newRow("IsoDate - valid, start of day, omit seconds") << QString::fromLatin1("00:00") << Qt::ISODate << QTime(0, 0, 0);
QTest::newRow("IsoDate - valid, omit seconds") << QString::fromLatin1("22:21") << Qt::ISODate << QTime(22, 21, 0);
QTest::newRow("IsoDate - valid, start of day, omit seconds") << u"00:00"_s << Qt::ISODate << QTime(0, 0, 0);
QTest::newRow("IsoDate - valid, omit seconds") << u"22:21"_s << Qt::ISODate << QTime(22, 21, 0);
QTest::newRow("IsoDate - minute fraction") // 60 * 0.816666 = 48.99996 should round up:
<< QString::fromLatin1("22:21.816666") << Qt::ISODate << QTime(22, 21, 49);
QTest::newRow("IsoDate - valid, omit seconds (2)") << QString::fromLatin1("23:59") << Qt::ISODate << QTime(23, 59, 0);
QTest::newRow("IsoDate - valid, end of day") << QString::fromLatin1("23:59:59") << Qt::ISODate << QTime(23, 59, 59);
<< u"22:21.816666"_s << Qt::ISODate << QTime(22, 21, 49);
QTest::newRow("IsoDate - valid, omit seconds (2)") << u"23:59"_s << Qt::ISODate << QTime(23, 59, 0);
QTest::newRow("IsoDate - valid, end of day") << u"23:59:59"_s << Qt::ISODate << QTime(23, 59, 59);
QTest::newRow("IsoDate - invalid, empty string") << QString::fromLatin1("") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, too many hours") << QString::fromLatin1("25:00") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, too many minutes") << QString::fromLatin1("10:70") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, empty string") << u""_s << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, too many hours") << u"25:00"_s << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, too many minutes") << u"10:70"_s << Qt::ISODate << invalidTime();
// This is a valid time if it happens on June 30 or December 31 (leap seconds).
QTest::newRow("IsoDate - invalid, too many seconds") << QString::fromLatin1("23:59:60") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, not enough minutes") << QString::fromLatin1("23:0") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, minute fraction") << QString::fromLatin1("23:00,XX") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::ISODate
QTest::newRow("IsoDate - invalid, too many seconds") << u"23:59:60"_s << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, minutes") << u"23:XX:00"_s << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, not enough minutes") << u"23:0"_s << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, minute fraction") << u"23:00,XX"_s << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, seconds") << u"23:00:XX"_s << Qt::ISODate << invalidTime();
QTest::newRow("IsoDate - invalid, milliseconds") << u"23:01:01:XXXX"_s << Qt::ISODate
<< invalidTime();
QTest::newRow("IsoDate - zero") << QString("00:00:00") << Qt::ISODate << QTime(0, 0);
QTest::newRow("IsoDate - ordinary") << QString("10:12:34") << Qt::ISODate << QTime(10, 12, 34);
QTest::newRow("IsoDate - zero") << u"00:00:00"_s << Qt::ISODate << QTime(0, 0);
QTest::newRow("IsoDate - ordinary") << u"10:12:34"_s << Qt::ISODate << QTime(10, 12, 34);
QTest::newRow("IsoDate - milli-max")
<< QString("19:03:54.998601") << Qt::ISODate << QTime(19, 3, 54, 999);
<< u"19:03:54.998601"_s << Qt::ISODate << QTime(19, 3, 54, 999);
QTest::newRow("IsoDate - milli-wrap")
<< QString("19:03:54.999601") << Qt::ISODate << QTime(19, 3, 55);
<< u"19:03:54.999601"_s << Qt::ISODate << QTime(19, 3, 55);
QTest::newRow("IsoDate - midnight-nowrap")
<< QString("23:59:59.9999") << Qt::ISODate << QTime(23, 59, 59, 999);
<< u"23:59:59.9999"_s << Qt::ISODate << QTime(23, 59, 59, 999);
QTest::newRow("IsoDate - midnight 24")
<< QString("24:00:00") << Qt::ISODate << QTime(0, 0);
<< u"24:00:00"_s << Qt::ISODate << QTime(0, 0);
QTest::newRow("IsoDate - minute fraction midnight")
<< QString("24:00,0") << Qt::ISODate << QTime(0, 0);
<< u"24:00,0"_s << Qt::ISODate << QTime(0, 0);
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
QTest::newRow("RFC 2822") << u"13 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 after space")
<< QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
<< u" 13 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 with day") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
QTest::newRow("RFC 2822 with day") << u"Thu, 01 Jan 1970 00:12:34 +0000"_s
<< Qt::RFC2822Date << QTime(0, 12, 34);
QTest::newRow("RFC 2822 with day after space")
<< QString::fromLatin1(" Thu, 01 Jan 1970 00:12:34 +0000")
<< u" Thu, 01 Jan 1970 00:12:34 +0000"_s
<< Qt::RFC2822Date << QTime(0, 12, 34);
// No timezone
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
QTest::newRow("RFC 2822 no timezone") << u"01 Jan 1970 00:12:34"_s
<< Qt::RFC2822Date << QTime(0, 12, 34);
// No time specified
QTest::newRow("RFC 2822 date only") << QString::fromLatin1("01 Nov 2002")
QTest::newRow("RFC 2822 date only") << u"01 Nov 2002"_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 2822 with day date only") << QString::fromLatin1("Fri, 01 Nov 2002")
QTest::newRow("RFC 2822 with day date only") << u"Fri, 01 Nov 2002"_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 2822 malformed time")
<< QString::fromLatin1("01 Nov 2002 0:") << Qt::RFC2822Date << QTime();
<< u"01 Nov 2002 0:"_s << Qt::RFC2822Date << QTime();
// Test invalid month, day, year are ignored:
QTest::newRow("RFC 2822 invalid month name") << QString::fromLatin1("13 Fev 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid month name") << u"13 Fev 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 invalid day") << QString::fromLatin1("36 Feb 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid day") << u"36 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 invalid day name") << QString::fromLatin1("Mud, 23 Feb 1987 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid day name") << u"Mud, 23 Feb 1987 13:24:51 +0100"_s
<< Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Feb 0000 13:24:51 +0100")
QTest::newRow("RFC 2822 invalid year") << u"13 Feb 0000 13:24:51 +0100"_s
<< Qt::RFC2822Date << QTime(13, 24, 51);
// Test invalid characters:
QTest::newRow("RFC 2822 invalid character at end")
<< QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
<< u"01 Jan 2012 08:00:00 +0100!"_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 2822 invalid character at front")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100")
<< u"!01 Jan 2012 08:00:00 +0100"_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 2822 invalid character both ends")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!")
<< u"!01 Jan 2012 08:00:00 +0100!"_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 2822 invalid character at front, 2 at back")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..")
<< u"!01 Jan 2012 08:00:00 +0100.."_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 2822 invalid character 2 at front")
<< QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100")
<< u"!!01 Jan 2012 08:00:00 +0100"_s
<< Qt::RFC2822Date << invalidTime();
// The common date text used by the "invalid character" tests, just to be
// sure *it's* not what's invalid:
QTest::newRow("RFC 2822 (not invalid)")
<< QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
<< u"01 Jan 2012 08:00:00 +0100"_s
<< Qt::RFC2822Date << QTime(8, 0, 0);
// Test Qt::RFC2822Date format (RFC 850 and 1036, permissive).
QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100")
QTest::newRow("RFC 850 and 1036") << u"Fri Feb 13 13:24:51 1987 +0100"_s
<< Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 850 and 1036 after space")
<< QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
<< u" Fri Feb 13 13:24:51 1987 +0100"_s
<< Qt::RFC2822Date << QTime(13, 24, 51);
// No timezone
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
QTest::newRow("RFC 850 and 1036 no timezone") << u"Thu Jan 01 00:12:34 1970"_s
<< Qt::RFC2822Date << QTime(0, 12, 34);
// No time specified
QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002")
QTest::newRow("RFC 850 and 1036 date only") << u"Fri Nov 01 2002"_s
<< Qt::RFC2822Date << invalidTime();
// Test invalid characters.
QTest::newRow("RFC 850 and 1036 invalid character at end")
<< QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
<< u"Sun Jan 01 08:00:00 2012 +0100!"_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 850 and 1036 invalid character at front")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100")
<< u"!Sun Jan 01 08:00:00 2012 +0100"_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 850 and 1036 invalid character both ends")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!")
<< u"!Sun Jan 01 08:00:00 2012 +0100!"_s
<< Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..")
<< u"!Sun Jan 01 08:00:00 2012 +0100.."_s
<< Qt::RFC2822Date << invalidTime();
// The common date text used by the "invalid character" tests, just to be
// sure *it's* not what's invalid:
QTest::newRow("RFC 850 and 1036 no invalid character")
<< QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100")
<< u"Sun Jan 01 08:00:00 2012 +0100"_s
<< Qt::RFC2822Date << QTime(8, 0, 0);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << invalidTime();
QTest::newRow("RFC empty") << u""_s << Qt::RFC2822Date << invalidTime();
}
void tst_QTime::fromStringDateFormat()
@ -594,18 +596,18 @@ void tst_QTime::toStringDateFormat_data()
QTest::addColumn<Qt::DateFormat>("format");
QTest::addColumn<QString>("expected");
QTest::newRow("00:00:00.000") << QTime(0, 0, 0, 0) << Qt::TextDate << QString("00:00:00");
QTest::newRow("ISO 00:00:00.000") << QTime(0, 0, 0, 0) << Qt::ISODate << QString("00:00:00");
QTest::newRow("Text 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::TextDate << QString("10:12:34");
QTest::newRow("ISO 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::ISODate << QString("10:12:34");
QTest::newRow("Text 10:12:34.001") << QTime(10, 12, 34, 001) << Qt::TextDate << QString("10:12:34");
QTest::newRow("ISO 10:12:34.001") << QTime(10, 12, 34, 001) << Qt::ISODate << QString("10:12:34");
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");
QTest::newRow("00:00:00.000") << QTime(0, 0, 0, 0) << Qt::TextDate << u"00:00:00"_s;
QTest::newRow("ISO 00:00:00.000") << QTime(0, 0, 0, 0) << Qt::ISODate << u"00:00:00"_s;
QTest::newRow("Text 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::TextDate << u"10:12:34"_s;
QTest::newRow("ISO 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::ISODate << u"10:12:34"_s;
QTest::newRow("Text 10:12:34.001") << QTime(10, 12, 34, 001) << Qt::TextDate << u"10:12:34"_s;
QTest::newRow("ISO 10:12:34.001") << QTime(10, 12, 34, 001) << Qt::ISODate << u"10:12:34"_s;
QTest::newRow("Text 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::TextDate << u"10:12:34"_s;
QTest::newRow("ISO 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::ISODate << u"10:12:34"_s;
QTest::newRow("RFC2822Date") << QTime(10, 12, 34, 999) << Qt::RFC2822Date << u"10:12:34"_s;
QTest::newRow("ISOWithMs 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::ISODateWithMs << u"10:12:34.000"_s;
QTest::newRow("ISOWithMs 10:12:34.020") << QTime(10, 12, 34, 20) << Qt::ISODateWithMs << u"10:12:34.020"_s;
QTest::newRow("ISOWithMs 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::ISODateWithMs << u"10:12:34.999"_s;
}
void tst_QTime::toStringDateFormat()
@ -623,14 +625,14 @@ void tst_QTime::toStringFormat_data()
QTest::addColumn<QString>("format");
QTest::addColumn<QString>("str");
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();
QTest::newRow( "empty format" ) << QTime(4,5,6,6) << QString("") << QString("");
QTest::newRow( "midnight" ) << QTime(0,0,0,0) << u"h:m:s:z"_s << u"0:0:0:0"_s;
QTest::newRow( "full" ) << QTime(10,12,34,53) << u"hh:mm:ss:zzz"_s << u"10:12:34:053"_s;
QTest::newRow( "short-msecs-lt100" ) << QTime(10,12,34,45) << u"hh:m:ss:z"_s << u"10:12:34:045"_s;
QTest::newRow( "short-msecs-gt100" ) << QTime(10,12,34,450) << u"hh:m:ss:z"_s << u"10:12:34:45"_s;
QTest::newRow( "am-pm" ) << QTime(10,12,34,45) << u"hh:ss ap"_s << u"10:34 am"_s;
QTest::newRow( "AM-PM" ) << QTime(22,12,34,45) << u"hh:zzz AP"_s << u"10:045 PM"_s;
QTest::newRow( "invalid" ) << QTime(230,230,230,230) << u"hh:mm:ss"_s << QString();
QTest::newRow( "empty format" ) << QTime(4,5,6,6) << u""_s << u""_s;
}
void tst_QTime::toStringFormat()
@ -677,10 +679,7 @@ void tst_QTime::msecsSinceStartOfDay()
QTime time = QTime::fromMSecsSinceStartOfDay(msecs);
QCOMPARE(time.isValid(), isValid);
if (msecs >= 0)
QCOMPARE(time.msecsSinceStartOfDay(), msecs);
else
QCOMPARE(time.msecsSinceStartOfDay(), 0);
QCOMPARE(time.msecsSinceStartOfDay(), msecs < 0 ? 0 : msecs);
QCOMPARE(time.hour(), hour);
QCOMPARE(time.minute(), minute);
QCOMPARE(time.second(), second);

View File

@ -15,6 +15,8 @@ qt_internal_add_test(tst_qtimezone
SOURCES
tst_qtimezone.cpp
DEFINES
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_FOREACH
QT_NO_KEYWORDS
LIBRARIES

View File

@ -127,7 +127,7 @@ void tst_QTimeZone::printTimeZone(const QTimeZone &tz)
qDebug() << "Name Short Generic = " << tz.displayName(QTimeZone::GenericTime, QTimeZone::ShortName);
qDebug() << "Name Offset Generic = " << tz.displayName(QTimeZone::GenericTime, QTimeZone::OffsetName);
qDebug() << "";
QLocale locale = QLocale(QStringLiteral("de_DE"));
QLocale locale = QLocale(u"de_DE");
qDebug() << "Locale = " << locale.name();
qDebug() << "Name Long = " << tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName, locale);
qDebug() << "Name Short = " << tz.displayName(QTimeZone::StandardTime, QTimeZone::ShortName, locale);
@ -1330,9 +1330,9 @@ void tst_QTimeZone::utcTest()
// Test default UTC constructor
QUtcTimeZonePrivate tzp;
QCOMPARE(tzp.isValid(), true);
QCOMPARE(tzp.id(), QByteArray("UTC"));
QCOMPARE(tzp.id(), "UTC");
QCOMPARE(tzp.territory(), QLocale::AnyTerritory);
QCOMPARE(tzp.abbreviation(0), QString("UTC"));
QCOMPARE(tzp.abbreviation(0), u"UTC");
QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()), utcLongName);
QCOMPARE(tzp.offsetFromUtc(0), 0);
QCOMPARE(tzp.standardTimeOffset(0), 0);
@ -1345,9 +1345,9 @@ void tst_QTimeZone::utcTest()
const QDateTime now = QDateTime::currentDateTime();
auto tz = QTimeZone::utc();
QCOMPARE(tz.isValid(), true);
QCOMPARE(tz.id(), QByteArrayLiteral("UTC"));
QCOMPARE(tz.id(), "UTC");
QCOMPARE(tz.territory(), QLocale::AnyTerritory);
QCOMPARE(tz.abbreviation(now), QStringLiteral("UTC"));
QCOMPARE(tz.abbreviation(now), u"UTC");
QCOMPARE(tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()), utcLongName);
QCOMPARE(tz.offsetFromUtc(now), 0);
QCOMPARE(tz.standardTimeOffset(now), 0);
@ -1358,14 +1358,14 @@ void tst_QTimeZone::utcTest()
// Test create from UTC Offset:
tz = QTimeZone(36000);
QVERIFY(tz.isValid());
QCOMPARE(tz.id(), QByteArray("UTC+10:00"));
QCOMPARE(tz.id(), "UTC+10:00");
QCOMPARE(tz.offsetFromUtc(now), 36000);
QCOMPARE(tz.standardTimeOffset(now), 36000);
QCOMPARE(tz.daylightTimeOffset(now), 0);
tz = QTimeZone(15 * 3600); // no IANA ID, so uses minimal id, skipping :00 minutes
QVERIFY(tz.isValid());
QCOMPARE(tz.id(), QByteArray("UTC+15"));
QCOMPARE(tz.id(), "UTC+15");
QCOMPARE(tz.offsetFromUtc(now), 15 * 3600);
QCOMPARE(tz.standardTimeOffset(now), 15 * 3600);
QCOMPARE(tz.daylightTimeOffset(now), 0);
@ -1383,20 +1383,20 @@ void tst_QTimeZone::utcTest()
// Test create from standard name (preserves :00 for minutes in id):
tz = QTimeZone("UTC+10:00");
QVERIFY(tz.isValid());
QCOMPARE(tz.id(), QByteArray("UTC+10:00"));
QCOMPARE(tz.id(), "UTC+10:00");
QCOMPARE(tz.offsetFromUtc(now), 36000);
QCOMPARE(tz.standardTimeOffset(now), 36000);
QCOMPARE(tz.daylightTimeOffset(now), 0);
// Test create custom zone
tz = QTimeZone("QST"_ba, 23456,
tz = QTimeZone("QST", 23456,
u"Qt Standard Time"_s, u"QST"_s, QLocale::Norway, u"Qt Testing"_s);
QCOMPARE(tz.isValid(), true);
QCOMPARE(tz.id(), "QST"_ba);
QCOMPARE(tz.comment(), u"Qt Testing"_s);
QCOMPARE(tz.id(), "QST");
QCOMPARE(tz.comment(), u"Qt Testing");
QCOMPARE(tz.territory(), QLocale::Norway);
QCOMPARE(tz.abbreviation(now), u"QST"_s);
QCOMPARE(tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName), u"Qt Standard Time"_s);
QCOMPARE(tz.abbreviation(now), u"QST");
QCOMPARE(tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName), u"Qt Standard Time");
QCOMPARE(tz.offsetFromUtc(now), 23456);
QCOMPARE(tz.standardTimeOffset(now), 23456);
QCOMPARE(tz.daylightTimeOffset(now), 0);
@ -1404,8 +1404,7 @@ void tst_QTimeZone::utcTest()
// Relies on local variable names: zone tzp and locale enUS.
#define ZONE_DNAME_CHECK(type, name, val) \
QCOMPARE(tzp.displayName(QTimeZone::type, QTimeZone::name, enUS), \
QStringLiteral(val));
QCOMPARE(tzp.displayName(QTimeZone::type, QTimeZone::name, enUS), val);
void tst_QTimeZone::icuTest()
{
@ -1432,20 +1431,20 @@ void tst_QTimeZone::icuTest()
if constexpr (debug) {
// Test display names by type
QLocale enUS("en_US");
ZONE_DNAME_CHECK(StandardTime, LongName, "Central European Standard Time");
ZONE_DNAME_CHECK(StandardTime, ShortName, "GMT+01:00");
ZONE_DNAME_CHECK(StandardTime, OffsetName, "UTC+01:00");
ZONE_DNAME_CHECK(DaylightTime, LongName, "Central European Summer Time");
ZONE_DNAME_CHECK(DaylightTime, ShortName, "GMT+02:00");
ZONE_DNAME_CHECK(DaylightTime, OffsetName, "UTC+02:00");
ZONE_DNAME_CHECK(StandardTime, LongName, u"Central European Standard Time");
ZONE_DNAME_CHECK(StandardTime, ShortName, u"GMT+01:00");
ZONE_DNAME_CHECK(StandardTime, OffsetName, u"UTC+01:00");
ZONE_DNAME_CHECK(DaylightTime, LongName, u"Central European Summer Time");
ZONE_DNAME_CHECK(DaylightTime, ShortName, u"GMT+02:00");
ZONE_DNAME_CHECK(DaylightTime, OffsetName, u"UTC+02:00");
// ICU C api does not support Generic Time yet, C++ api does
ZONE_DNAME_CHECK(GenericTime, LongName, "Central European Standard Time");
ZONE_DNAME_CHECK(GenericTime, ShortName, "GMT+01:00");
ZONE_DNAME_CHECK(GenericTime, OffsetName, "UTC+01:00");
ZONE_DNAME_CHECK(GenericTime, LongName, u"Central European Standard Time");
ZONE_DNAME_CHECK(GenericTime, ShortName, u"GMT+01:00");
ZONE_DNAME_CHECK(GenericTime, OffsetName, u"UTC+01:00");
// Test Abbreviations
QCOMPARE(tzp.abbreviation(std), QString("CET"));
QCOMPARE(tzp.abbreviation(dst), QString("CEST"));
QCOMPARE(tzp.abbreviation(std), u"CET");
QCOMPARE(tzp.abbreviation(dst), u"CEST");
}
testCetPrivate(tzp);
@ -1509,7 +1508,7 @@ void tst_QTimeZone::tzTest()
QCOMPARE(tzBrazil.offsetFromUtc(QDateTime(QDate(1111, 11, 11).startOfDay())), -10800);
// Test display names by type, either ICU or abbreviation only
QLocale enUS("en_US");
QLocale enUS(u"en_US");
// Only test names in debug mode, names used can vary by ICU version installed
if constexpr (debug) {
#if QT_CONFIG(icu)
@ -1536,8 +1535,8 @@ void tst_QTimeZone::tzTest()
#endif // icu
// Test Abbreviations
QCOMPARE(tzp.abbreviation(std), QString("CET"));
QCOMPARE(tzp.abbreviation(dst), QString("CEST"));
QCOMPARE(tzp.abbreviation(std), u"CET");
QCOMPARE(tzp.abbreviation(dst), u"CEST");
}
testCetPrivate(tzp);
@ -1557,7 +1556,7 @@ void tst_QTimeZone::tzTest()
QTimeZonePrivate::Data dat = tzp.data(ancient);
QCOMPARE(dat.atMSecsSinceEpoch, ancient);
QCOMPARE(dat.daylightTimeOffset, 0);
if (dat.abbreviation == "LMT") {
if (dat.abbreviation == u"LMT") {
QCOMPARE(dat.standardTimeOffset, 3208);
} else {
QCOMPARE(dat.standardTimeOffset, 3600);
@ -1600,7 +1599,7 @@ void tst_QTimeZone::tzTest()
QCOMPARE(dat.daylightTimeOffset, 3600);
dat = tzp.previousTransition(stdHi);
QCOMPARE(dat.abbreviation, QStringLiteral("CET"));
QCOMPARE(dat.abbreviation, u"CET");
QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, UTC),
QDateTime(QDate(2099, 10, 25), QTime(3, 0), QTimeZone::fromSecondsAheadOfUtc(7200)));
QCOMPARE(dat.offsetFromUtc, 3600);
@ -1608,7 +1607,7 @@ void tst_QTimeZone::tzTest()
QCOMPARE(dat.daylightTimeOffset, 0);
dat = tzp.previousTransition(dstHi);
QCOMPARE(dat.abbreviation, QStringLiteral("CEST"));
QCOMPARE(dat.abbreviation, u"CEST");
QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, UTC),
QDateTime(QDate(2100, 3, 28), QTime(2, 0), QTimeZone::fromSecondsAheadOfUtc(3600)));
QCOMPARE(dat.offsetFromUtc, 7200);
@ -1616,7 +1615,7 @@ void tst_QTimeZone::tzTest()
QCOMPARE(dat.daylightTimeOffset, 3600);
dat = tzp.nextTransition(stdHi);
QCOMPARE(dat.abbreviation, QStringLiteral("CEST"));
QCOMPARE(dat.abbreviation, u"CEST");
QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, UTC),
QDateTime(QDate(2100, 3, 28), QTime(2, 0), QTimeZone::fromSecondsAheadOfUtc(3600)));
QCOMPARE(dat.offsetFromUtc, 7200);
@ -1624,7 +1623,7 @@ void tst_QTimeZone::tzTest()
QCOMPARE(dat.daylightTimeOffset, 3600);
dat = tzp.nextTransition(dstHi);
QCOMPARE(dat.abbreviation, QStringLiteral("CET"));
QCOMPARE(dat.abbreviation, u"CET");
QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch,
QTimeZone::fromSecondsAheadOfUtc(3600)),
QDateTime(QDate(2100, 10, 31), QTime(3, 0), QTimeZone::fromSecondsAheadOfUtc(7200)));
@ -1656,11 +1655,11 @@ void tst_QTimeZone::tzTest()
// Test a timezone with an abbreviation that isn't all letters:
QTzTimeZonePrivate tzBarnaul("Asia/Barnaul");
if (tzBarnaul.isValid()) {
QCOMPARE(tzBarnaul.data(std).abbreviation, QString("+07"));
QCOMPARE(tzBarnaul.data(std).abbreviation, u"+07");
// first full day of the new rule (tzdata2016b)
QDateTime dt(QDate(2016, 3, 28), QTime(0, 0), UTC);
QCOMPARE(tzBarnaul.data(dt.toMSecsSinceEpoch()).abbreviation, QString("+07"));
QCOMPARE(tzBarnaul.data(dt.toMSecsSinceEpoch()).abbreviation, u"+07");
}
#endif // QT_BUILD_INTERNAL && Q_OS_UNIX && !timezone_tzdb && !Q_OS_DARWIN && !Q_OS_ANDROID
}
@ -1687,7 +1686,7 @@ void tst_QTimeZone::macTest()
// Only test names in debug mode, names used can vary by version
if constexpr (debug) {
// Test display names by type
QLocale enUS("en_US");
QLocale enUS(u"en_US");
ZONE_DNAME_CHECK(StandardTime, LongName, "Central European Standard Time");
ZONE_DNAME_CHECK(StandardTime, ShortName, "GMT+01:00");
ZONE_DNAME_CHECK(StandardTime, OffsetName, "UTC+01:00");
@ -1700,8 +1699,8 @@ void tst_QTimeZone::macTest()
ZONE_DNAME_CHECK(GenericTime, OffsetName, "UTC+01:00");
// Test Abbreviations
QCOMPARE(tzp.abbreviation(std), QString("CET"));
QCOMPARE(tzp.abbreviation(dst), QString("CEST"));
QCOMPARE(tzp.abbreviation(std), u"CET");
QCOMPARE(tzp.abbreviation(dst), u"CEST");
}
testCetPrivate(tzp);
@ -1747,7 +1746,7 @@ void tst_QTimeZone::winTest()
// Only test names in debug mode, names used can vary by version
if constexpr (debug) {
// Test display names by type
QLocale enUS("en_US");
QLocale enUS(u"en_US");
ZONE_DNAME_CHECK(StandardTime, LongName, "W. Europe Standard Time");
ZONE_DNAME_CHECK(StandardTime, ShortName, "W. Europe Standard Time");
ZONE_DNAME_CHECK(StandardTime, OffsetName, "UTC+01:00");
@ -1761,8 +1760,8 @@ void tst_QTimeZone::winTest()
ZONE_DNAME_CHECK(GenericTime, OffsetName, "UTC+01:00");
// Test Abbreviations
QCOMPARE(tzp.abbreviation(std), QString("CET"));
QCOMPARE(tzp.abbreviation(dst), QString("CEST"));
QCOMPARE(tzp.abbreviation(std), u"CET");
QCOMPARE(tzp.abbreviation(dst), u"CEST");
}
testCetPrivate(tzp);