Check for both A and P when converting QDateTime to string.

hasUnquotedAP currently only checks for an a or A, which is wrong
according to both the toString documentation and the comments for
hasUnquotedAP.

Change-Id: I03015734b846fe761085cf8f8fca2b29210cff97
Reviewed-by: Jon Severinsson <jon@severinsson.net>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
bb10
Mitch Curtis 2012-10-18 18:51:20 +02:00 committed by The Qt Project
parent d3c1a9f387
commit 6497649730
2 changed files with 6 additions and 3 deletions

View File

@ -3743,7 +3743,8 @@ static bool hasUnquotedAP(const QString &f)
for (int i=0; i<max; ++i) {
if (f.at(i) == quote) {
inquote = !inquote;
} else if (!inquote && f.at(i).toUpper() == QLatin1Char('A')) {
} else if (!inquote && f.at(i).toUpper() == QLatin1Char('A')
&& i + 1 < max && f.at(i + 1).toUpper() == QLatin1Char('P')) {
return true;
}
}

View File

@ -1352,8 +1352,6 @@ void tst_QDateTime::toString_strformat_data()
<< QString("d'foobar'") << QString("31foobar");
QTest::newRow( "datetime9" ) << QDateTime(QDate(1999, 12, 31), QTime(3, 59, 59, 999))
<< QString("hhhhh") << QString("03033");
QTest::newRow( "datetime10" ) << QDateTime(QDate(1999, 12, 31), QTime(3, 59, 59, 999))
<< QString("hhhhhaA") << QString("03033amAM");
QTest::newRow( "datetime11" ) << QDateTime(QDate(1999, 12, 31), QTime(23, 59, 59, 999))
<< QString("HHHhhhAaAPap") << QString("23231111PMpmPMpm");
QTest::newRow( "datetime12" ) << QDateTime(QDate(1999, 12, 31), QTime(3, 59, 59, 999))
@ -1361,6 +1359,10 @@ void tst_QDateTime::toString_strformat_data()
QTest::newRow( "datetime13" ) << QDateTime(QDate(1974, 12, 1), QTime(14, 14, 20))
<< QString("hh''mm''ss dd''MM''yyyy")
<< QString("14'14'20 01'12'1974");
QTest::newRow( "missing p and P" ) << QDateTime(QDate(1999, 12, 31), QTime(3, 59, 59, 999))
<< QString("hhhhhaA") << QString("03033aA");
QTest::newRow( "OK A, bad P" ) << QDateTime(QDate(1999, 12, 31), QTime(0, 59, 59, 999))
<< QString("hhAX") << QString("00AX");
}
void tst_QDateTime::toString_strformat()