Check for both A and P when converting QDateTime to string.
authorMitch Curtis <mitch.curtis@digia.com>
Thu, 18 Oct 2012 16:51:20 +0000 (18:51 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 29 Oct 2012 23:06:26 +0000 (00:06 +0100)
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>
src/corelib/tools/qdatetime.cpp
tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp

index 67dbbef..12f9335 100644 (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;
         }
     }
index 9e71a32..fc13cba 100644 (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()