diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-08-16 20:37:09 +0300 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-08-16 20:37:09 +0300 |
commit | b7d91087099e4b69d70c0271fbeae19368d485d4 (patch) | |
tree | f46b62227cfeccf32b72f6aeb45c17cc7a933505 /src/corelib/time/qdatetimeparser.cpp | |
parent | 231d3670981a33ec42b91ad1cb33c1fc50551066 (diff) | |
parent | bbfbb18df18658e8ceec4bc04bd2cdf59f6a35ed (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.6' into tqtc/lts-5.15-opensource
Change-Id: Ia9164a17d80376f0a3ab9752c4a9f4dd2f0bd3d9
Diffstat (limited to 'src/corelib/time/qdatetimeparser.cpp')
-rw-r--r-- | src/corelib/time/qdatetimeparser.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 540818fab4..c5e0493de5 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -1385,21 +1385,34 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, // If hour wasn't specified, check the default we're using exists on the // given date (which might be a spring-forward, skipping an hour). - if (parserType == QMetaType::QDateTime && !(isSet & HourSectionMask) && !when.isValid()) { - qint64 msecs = when.toMSecsSinceEpoch(); - // Fortunately, that gets a useful answer, even though when is invalid ... - const QDateTime replace = + if (!(isSet & HourSectionMask) && !when.isValid()) { + switch (parserType) { + case QMetaType::QDateTime: { + qint64 msecs = when.toMSecsSinceEpoch(); + // Fortunately, that gets a useful answer, even though when is invalid ... + const QDateTime replace = #if QT_CONFIG(timezone) - tspec == Qt::TimeZone - ? QDateTime::fromMSecsSinceEpoch(msecs, timeZone) : + tspec == Qt::TimeZone ? QDateTime::fromMSecsSinceEpoch(msecs, timeZone) : #endif - QDateTime::fromMSecsSinceEpoch(msecs, tspec, zoneOffset); - const QTime tick = replace.time(); - if (replace.date() == date - && (!(isSet & MinuteSection) || tick.minute() == minute) - && (!(isSet & SecondSection) || tick.second() == second) - && (!(isSet & MSecSection) || tick.msec() == msec)) { - return StateNode(replace, state, padding, conflicts); + QDateTime::fromMSecsSinceEpoch(msecs, tspec, zoneOffset); + const QTime tick = replace.time(); + if (replace.date() == date + && (!(isSet & MinuteSection) || tick.minute() == minute) + && (!(isSet & SecondSection) || tick.second() == second) + && (!(isSet & MSecSection) || tick.msec() == msec)) { + return StateNode(replace, state, padding, conflicts); + } + } break; + case QMetaType::QDate: + // Don't care about time, so just use start of day (and ignore spec): + return StateNode(date.startOfDay(Qt::UTC), state, padding, conflicts); + break; + case QMetaType::QTime: + // Don't care about date or spec, so pick a safe spec: + return StateNode(QDateTime(date, time, Qt::UTC), state, padding, conflicts); + default: + Q_UNREACHABLE(); + return StateNode(); } } |