diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-10 16:47:02 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-19 13:56:36 +0200 |
commit | 7aada633be93f581f32079610cb3db9800680449 (patch) | |
tree | c8b45317a30d3f7ab9c5991ebb70c8a3dc10df52 | |
parent | 24f5e48fba15ef1954f8c552db961b9141269c98 (diff) |
QTZP_TZ: make PosixZone default constructor replace its invalid()
The type is always constructed by brace-initialization otherwise, so
just NSDMI-ing its offset to InvalidOffset simplifies the handling of
invalid values.
Task-number: QTBUG-122619
Change-Id: Ic7173fe6572bf700bb5858a2553750023c267160
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/time/qtimezoneprivate_tz.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index c046dd881d..8c6a32edc9 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -521,12 +521,10 @@ struct PosixZone }; QString name; - int offset; + int offset = InvalidOffset; + bool hasValidOffset() const noexcept { return offset != InvalidOffset; } - static PosixZone invalid() { return {QString(), InvalidOffset}; } static PosixZone parse(const char *&pos, const char *end); - - bool hasValidOffset() const noexcept { return offset != InvalidOffset; } }; } // unnamed namespace @@ -557,7 +555,7 @@ PosixZone PosixZone::parse(const char *&pos, const char *end) pos = nameEnd; } if (nameEnd - nameBegin < 3) - return invalid(); // name must be at least 3 characters long + return {}; // name must be at least 3 characters long // zone offset, form [+-]hh:mm:ss const char *zoneBegin = pos; @@ -576,7 +574,7 @@ PosixZone PosixZone::parse(const char *&pos, const char *end) // UTC+hh:mm:ss or GMT+hh:mm:ss should be read as offsets from UTC, not as a // POSIX rule naming a zone as UTC or GMT and specifying a non-zero offset. if (offset != 0 && (name =="UTC"_L1 || name == "GMT"_L1)) - return invalid(); + return {}; return {std::move(name), offset}; } @@ -646,7 +644,7 @@ static QList<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray // and the link in validatePosixRule(), above. QList<QByteArray> parts = posixRule.split(','); - PosixZone stdZone, dstZone = PosixZone::invalid(); + PosixZone stdZone, dstZone; { const QByteArray &zoneinfo = parts.at(0); const char *begin = zoneinfo.constBegin(); |