Skip to content

Commit

Permalink
[qtbase] Fix QDateTime::toString() timezone info. Contributes to JB#5…
Browse files Browse the repository at this point in the history
…3010

Prior to commit 7c33c64 upstream, the time zone offset is not appended
to string generated by toString with the Qt::ISODate format. The present
commit is a rewrite of the upstream commit targetting 5.6. The present
commit can be safely ignored when moving to 5.9 or more recent versions
of Qt.

It is somehow related to QT-26161.
  • Loading branch information
dcaliste committed Feb 3, 2021
1 parent 567a894 commit 74afde0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/corelib/tools/qdatetime.cpp
Expand Up @@ -3565,7 +3565,11 @@ QString QDateTime::toString(Qt::DateFormat format) const
.arg(dt.day())
.arg(tm.toString(Qt::TextDate))
.arg(dt.year());
if (timeSpec() != Qt::LocalTime) {
if (timeSpec() == Qt::TimeZone) {
#ifndef QT_BOOTSTRAPPED
buf += QStringLiteral(" ") + d->m_timeZone.d->abbreviation(d->toMSecsSinceEpoch());
#endif
} else if (timeSpec() != Qt::LocalTime) {
buf += QStringLiteral(" GMT");
if (d->m_spec == Qt::OffsetFromUTC)
buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc);
Expand All @@ -3587,6 +3591,9 @@ QString QDateTime::toString(Qt::DateFormat format) const
buf += QLatin1Char('Z');
break;
case Qt::OffsetFromUTC:
#ifndef QT_BOOTSTRAPPED
case Qt::TimeZone:
#endif
buf += toOffsetString(Qt::ISODate, d->m_offsetFromUtc);
break;
default:
Expand Down

0 comments on commit 74afde0

Please sign in to comment.