summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2020-05-13 15:12:28 +0300
committerAndrei Golubev <andrei.golubev@qt.io>2020-05-28 11:48:57 +0300
commitcfbb30decda13fb630127246af5bea32c5f4da57 (patch)
tree8aa60081af1949bf9b4fc276f163861b4cb07d80 /src/corelib
parent33fc6226865ab4b36a452e733e4519e45fea691d (diff)
Make QDateTimeParser recognize local time offsets
Fixes: QTBUG-84209 Pick-to: 5.15 Change-Id: Iedbc7beafcaa55c72fec3ac5a5f519c6ed5f7770 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/time/qdatetimeparser.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp
index e5242b43eb..68ec73f471 100644
--- a/src/corelib/time/qdatetimeparser.cpp
+++ b/src/corelib/time/qdatetimeparser.cpp
@@ -1726,29 +1726,26 @@ QDateTimeParser::ParsedSection QDateTimeParser::findUtcOffset(QStringRef str) co
QDateTimeParser::ParsedSection
QDateTimeParser::findTimeZoneName(QStringRef str, const QDateTime &when) const
{
- int index = startsWithLocalTimeZone(str);
- if (index > 0) // won't actually use the offset, but need it to be valid
- return ParsedSection(Acceptable, when.toLocalTime().offsetFromUtc(), index);
-
+ const int systemLength = startsWithLocalTimeZone(str);
#if QT_CONFIG(timezone)
- const int size = str.length();
-
// Collect up plausibly-valid characters; let QTimeZone work out what's
// truly valid.
- for (; index < size; ++index) {
- const QChar here = str[index];
- if (here >= 127 || (!here.isLetterOrNumber() && !QLatin1String("/-_.+:").contains(here)))
- break;
- }
+ const auto invalidZoneNameCharacter = [] (const QChar &c) {
+ return c.unicode() >= 127u
+ || (!c.isLetterOrNumber() && !QLatin1String("+-./:_").contains(c));
+ };
+ int index = std::distance(str.cbegin(),
+ std::find_if(str.cbegin(), str.cend(), invalidZoneNameCharacter));
- while (index > 0) {
+ for (; index > systemLength; --index) { // Find longest match
str.truncate(index);
QTimeZone zone(str.toLatin1());
if (zone.isValid())
return ParsedSection(Acceptable, zone.offsetFromUtc(when), index);
- index--; // maybe we collected too much ...
}
#endif
+ if (systemLength > 0) // won't actually use the offset, but need it to be valid
+ return ParsedSection(Acceptable, when.toLocalTime().offsetFromUtc(), systemLength);
return ParsedSection();
}