diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-02-11 16:14:05 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-02-15 13:44:06 +0100 |
commit | 3cf84287e71d8698c46ce31a6daad71056db8027 (patch) | |
tree | 95a629c289d517e9c5d1d2ac9e1b839d875924a7 /src/corelib/time/qdatetime.cpp | |
parent | 73fbf8bd303053a091fc63d0ad741a071bb50fae (diff) |
Prepare TextDate to use UTC-offset rather than GMT-offset zone suffixes
There are GMT-offset zones whose convention for the sign of the offset
is the reverse of what we are (still) using, which is the usual
convention for UTC-offset zone: for example, the Olson Database's
Etc/GMT+3 has offset -3 hours in the UTC-based system we use, so we
give it suffix GMT-0300. The UTC-based suffix is also what we use as
the abbreviation for OffsetFromUTC() in toString().
For now this only adds support for parsing a planned future form: the
old form using GMT is retained, to give client code some chance to
prepare for a backwards-compatible transition. Although the GMT prefix
is matched case-insensitively, only match UTC if fully upper-case;
there is no meaningful precedent for case-insensitive usage here.
[ChangeLog][QtCore][QDateTime] The Qt::TextDate format now recognizes
UTC-based offset suffixes in addition to suffixes based on the
deprecated alias GMT. This prepares for toString() to use such
UTC-based suffixes for time-zones (fromString() cannot parse the
present abbreviation suffix). A future release of Qt shall use
UTC-based suffixes in place of the present GMT-based suffixes (which
conflict with GMT-based IANA zone names) for Qt::LocalTime and
Qt::OffsetFromUTC time-specs. Client code is encouraged to use and
recognize UTC-based zone suffixes in preparation for that transition,
unless compatibility with versions before 6.2 is required.
Change-Id: I5a42a488f1232a30f4b427b7954759283423b9b3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time/qdatetime.cpp')
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 9ad9c9c597..28b3cbb059 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -4033,7 +4033,11 @@ QString QDateTime::toString(Qt::DateFormat format) const break; #endif default: +#if 0 // ### Qt 7 GMT: use UTC instead, see qnamespace.qdoc documentation + buf += QLatin1String(" UTC"); +#else buf += QLatin1String(" GMT"); +#endif if (getSpec(d) == Qt::OffsetFromUTC) buf += toOffsetString(Qt::TextDate, offsetFromUtc()); } @@ -4933,17 +4937,17 @@ QDateTime QDateTime::fromString(QStringView string, Qt::DateFormat format) return QDateTime(date, time, Qt::LocalTime); QStringView tz = parts.at(5); - if (!tz.startsWith(QLatin1String("GMT"), Qt::CaseInsensitive)) - return QDateTime(); - tz = tz.sliced(3); - if (!tz.isEmpty()) { + if (tz.startsWith(QLatin1String("UTC")) + // GMT has long been deprecated as an alias for UTC. + || tz.startsWith(QLatin1String("GMT"), Qt::CaseInsensitive)) { + tz = tz.sliced(3); + if (tz.isEmpty()) + return QDateTime(date, time, Qt::UTC); + int offset = fromOffsetString(tz, &ok); - if (!ok) - return QDateTime(); - return QDateTime(date, time, Qt::OffsetFromUTC, offset); - } else { - return QDateTime(date, time, Qt::UTC); + return ok ? QDateTime(date, time, Qt::OffsetFromUTC, offset) : QDateTime(); } + return QDateTime(); } } |