summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@digia.com>2012-10-18 18:51:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-30 00:06:26 +0100
commit6497649730daeab5d3dfac7e806105e99a237656 (patch)
tree3ff5e196d5e0bef889a6fcae07f9428965aa3f7c
parentd3c1a9f38784c8d3a439517cc971320d74613869 (diff)
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>
-rw-r--r--src/corelib/tools/qdatetime.cpp3
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp6
2 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 67dbbef9ad..12f9335990 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -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;
}
}
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index 9e71a32f87..fc13cba28d 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -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()