diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2016-11-21 17:51:22 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2016-12-14 16:41:06 +0000 |
commit | f8ec940ab6ba265c9f8c8be68f8e4a487854e6ff (patch) | |
tree | a564aedd44022cca583109094b8f0c89265e8b25 | |
parent | ff4f0c327617e7d7593efdf986235296bf0b83d7 (diff) |
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 <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 12 |
1 files 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<QDate, QTime> 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: |