diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-04-27 14:39:50 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-05-11 13:46:42 +0200 |
commit | 9f1252da28033fdf46d57112905f2770970ca964 (patch) | |
tree | 5e892d8c064adf447e9a8d843c9eddf66645e12b /src | |
parent | cded6afa3590b7c83664ac6f75d817bfc9b85287 (diff) | |
download | qtbase-9f1252da28033fdf46d57112905f2770970ca964.tar.gz |
Fix QTimeZone::offsetData() for the case without transitions
A zone without transitions, such as any UTC-based one, would
previously return invalid data for the offset data at a given
time. The method was documented to be "the equivalent of calling
offsetFromUtc(), abbreviation(), etc" but these methods do return
sensible data for a zone with no transitions. Furthermore, the backend
data() method on which it depends is implemented by all backends,
including the UTC one, with no transitions.
Fix offsetData() to also return data when no transitions are
available. Improve docs.
Adapt the checkOffset() test to test offsetData() as well as the
various functions to get parts of it. In the process, change that test
to use a QTimeZone row instead of its name as a QByteArray, so that we
can also have rows for lightweight time representations.
Change-Id: I241ecf02a26a228cca972bca5e2db687fe41feb4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/time/qtimezone.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index 8f754549e8..f2a7eea0f8 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -1141,9 +1141,12 @@ bool QTimeZone::isDaylightTime(const QDateTime &atDateTime) const } /*! - Returns the effective offset details at the given \a forDateTime. This is - the equivalent of calling offsetFromUtc(), abbreviation(), etc individually but is - more efficient. + Returns the effective offset details at the given \a forDateTime. + + This is the equivalent of calling abbreviation() and all three offset + functions individually but is more efficient. If this data is not available + for the given datetime, an invalid OffsetData will be returned with an + invalid QDateTime as its \c atUtc. This method is only available when feature \c timezone is enabled. @@ -1163,9 +1166,9 @@ QTimeZone::OffsetData QTimeZone::offsetData(const QDateTime &forDateTime) const Q_UNREACHABLE(); break; } - } else if (hasTransitions()) { - return QTimeZonePrivate::toOffsetData(d->data(forDateTime.toMSecsSinceEpoch())); } + if (isValid()) + return QTimeZonePrivate::toOffsetData(d->data(forDateTime.toMSecsSinceEpoch())); return QTimeZonePrivate::invalidOffsetData(); } @@ -1206,7 +1209,7 @@ bool QTimeZone::hasTransitions() const Transition after it. If there is no transition after the given \a afterDateTime then an invalid - OffsetData will be returned with an invalid QDateTime. + OffsetData will be returned with an invalid QDateTime as its \c atUtc. The given \a afterDateTime is exclusive. @@ -1241,7 +1244,7 @@ QTimeZone::OffsetData QTimeZone::nextTransition(const QDateTime &afterDateTime) Transition before it. If there is no transition before the given \a beforeDateTime then an invalid - OffsetData will be returned with an invalid QDateTime. + OffsetData will be returned with an invalid QDateTime as its \c atUtc. The given \a beforeDateTime is exclusive. |