diff options
Diffstat (limited to 'src/corelib/time/qtimezone.cpp')
-rw-r--r-- | src/corelib/time/qtimezone.cpp | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index 558cb53a08..8ce967cf9f 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -455,10 +455,17 @@ QTimeZone::QTimeZone(const QByteArray &ianaId) d = new QUtcTimeZonePrivate(ianaId); // If not recognized, try creating it with the system backend. if (!d->isValid()) { - if (ianaId.isEmpty()) + if (ianaId.isEmpty()) { d = newBackendTimeZone(); - else // Constructor MUST produce invalid for unsupported ID. + } else { // Constructor MUST produce invalid for unsupported ID. d = newBackendTimeZone(ianaId); + if (!d->isValid()) { + // We may have a legacy alias for a supported IANA ID: + const QByteArray name = QTimeZonePrivate::aliasToIana(ianaId); + if (!name.isEmpty() && name != ianaId) + d = newBackendTimeZone(name); + } + } } // Can also handle UTC with arbitrary (valid) offset, but only do so as // fall-back, since either of the above may handle it more informatively. @@ -823,6 +830,34 @@ QByteArray QTimeZone::id() const } /*! + \since 6.8 + Returns \c true if \a alias is an alternative name for this timezone. + + The IANA (formerly Olson) database has renamed some zones during its + history. There are also some zones that only differed prior to 1970 but are + now treated as synonymous. Some backends may have data reaching to before + 1970 and produce distinct zones in the latter case. Others may produce zones + indistinguishable except by id(). This method determines whether an ID + refers (at least since 1970) to the same zone that this timezone object + describes. + + This method is only available when feature \c timezone is enabled. +*/ +bool QTimeZone::aliasMatches(QByteArrayView alias) const +{ + if (alias == id()) + return true; + QByteArray mine = QTimeZonePrivate::aliasToIana(id()); + // Empty if id() aliases to itself, which we've already checked: + if (!mine.isEmpty() && alias == mine) + return true; + QByteArray its = QTimeZonePrivate::aliasToIana(alias); + // Empty if alias aliases to itself, which we've already compared to id() + // and, where relevant, mine. + return !its.isEmpty() && its == (mine.isEmpty() ? id() : mine); +} + +/*! \since 6.2 Returns the territory for the time zone. @@ -908,7 +943,7 @@ QString QTimeZone::displayName(const QDateTime &atDateTime, NameType nameType, return systemTimeZone().displayName(atDateTime, nameType, locale); case Qt::UTC: case Qt::OffsetFromUTC: - return QUtcTimeZonePrivate(d.s.offset).QTimeZonePrivate::displayName( + return QUtcTimeZonePrivate(d.s.offset).displayName( atDateTime.toMSecsSinceEpoch(), nameType, locale); case Qt::TimeZone: Q_UNREACHABLE(); |