From f8ec940ab6ba265c9f8c8be68f8e4a487854e6ff Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 21 Nov 2016 17:51:22 +0100 Subject: [PATCH] Simplify QDateTime::toString(Qt::TextDate)'s text construction We can in fact delegate to QDate::toString(), contrary to the comment that was there; we just need to insert the time in the right place, which is easy enough to find. Change-Id: I66624724628d45ce283243879b102ec8f741a15f Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index c0a678fec0..01ed3cea5b 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3800,14 +3800,10 @@ QString QDateTime::toString(Qt::DateFormat format) const #ifndef QT_NO_TEXTDATE case Qt::TextDate: { const QPair p = getDateTime(d); - const QDate &dt = p.first; - const QTime &tm = p.second; - //We cant use date.toString(Qt::TextDate) as we need to insert the time before the year - buf = QString::fromLatin1("%1 %2 %3 %4 %5").arg(dt.shortDayName(dt.dayOfWeek())) - .arg(dt.shortMonthName(dt.month())) - .arg(dt.day()) - .arg(tm.toString(Qt::TextDate)) - .arg(dt.year()); + buf = p.first.toString(Qt::TextDate); + // Insert time between date's day and year: + buf.insert(buf.lastIndexOf(QLatin1Char(' ')), + QLatin1Char(' ') + p.second.toString(Qt::TextDate)); // Append zone/offset indicator, as appropriate: switch (timeSpec()) { case Qt::LocalTime: