From b4ee126a75e0f6f23ba9401352f30d5af8f4eccb Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 22 Feb 2021 16:45:03 +0100 Subject: [PATCH] Simplify QDateTimeParser::fromString() to always record the date-time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, *datetime was only written to if the parse was a success. When parsing a date-time that's invalid by virtue of falling in a spring-forward gap, the parser returns a date-time that is invalid but has a toMSecsSinceEpoch() suitable for use in creating a sensible interpretation of the parsed string (in offset by the width of the gap from the specified position in the gap). It is more useful to return this value than a default-created QDateTime. Change-Id: I89f39e729b1f9fede1532d8b82f6f676477ddadb Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Andrei Golubev --- src/corelib/time/qdatetimeparser.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index b17135ef36..d85a904450 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -2132,15 +2132,9 @@ bool QDateTimeParser::fromString(const QString &t, QDateTime* datetime) const { QDateTime val(QDate(1900, 1, 1).startOfDay()); const StateNode tmp = parse(t, -1, val, false); - if (tmp.state != Acceptable || tmp.conflicts) - return false; - if (datetime) { - if (!tmp.value.isValid()) - return false; + if (datetime) *datetime = tmp.value; - } - - return true; + return tmp.state == Acceptable && !tmp.conflicts && tmp.value.isValid(); } QDateTime QDateTimeParser::getMinimum() const