Output leading zeroes for yyyy date formats in QLocale::toString().
authorMitch Curtis <mitch.curtis@digia.com>
Fri, 21 Sep 2012 09:30:55 +0000 (11:30 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 23 Oct 2012 23:38:49 +0000 (01:38 +0200)
Converting the date 1 January 0001 to a string in the format
"dd MMMM yyyy" currently results in the string "01 January 1", but it
should be "01 January 0001".

Task-number: QTBUG-27287
Change-Id: Ia025da7343d1c36aaee34c47c6db551a6e89595f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/tools/qlocale.cpp
tests/auto/corelib/tools/qlocale/tst_qlocale.cpp

index 368cb44..97946b5 100644 (file)
@@ -2262,7 +2262,7 @@ QString QLocalePrivate::dateTimeToString(const QString &format, const QDate *dat
 
                 switch (repeat) {
                 case 4:
-                    result.append(longLongToString(date->year()));
+                    result.append(longLongToString(date->year(), -1, 10, 4, QLocalePrivate::ZeroPadded));
                     break;
                 case 2:
                     result.append(longLongToString(date->year() % 100, -1, 10, 2,
index a8aded5..299ae10 100644 (file)
@@ -875,6 +875,7 @@ void tst_QLocale::formatDate_data()
     QTest::newRow("28") << QDate() << "'\"yy\"'" << "";
     QTest::newRow("29") << QDate(1974, 12, 1) << "hh:mm:ss.zzz ap d'd'dd/M/yy" << "hh:mm:ss.zzz ap 1d01/12/74";
 
+    QTest::newRow("dd MMMM yyyy") << QDate(1, 1, 1) << "dd MMMM yyyy" << "01 January 0001";
 }
 
 void tst_QLocale::formatDate()
@@ -974,6 +975,9 @@ void tst_QLocale::formatDateTime_data()
     QTest::newRow("12C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
                          << "d'd'dd/M/yyh" << "1d01/12/7415";
 
+    QTest::newRow("dd MMMM yyyy, hh:mm:ss") << "C" << QDateTime(QDate(1, 1, 1), QTime(12, 00, 00))
+                         << "dd MMMM yyyy, hh:mm:ss" << "01 January 0001, 12:00:00";
+
     QTest::newRow("20C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
                          << "foo" << "foo";
     QTest::newRow("21C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))