diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-02-22 16:45:03 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-03-01 16:45:17 +0100 |
commit | b4ee126a75e0f6f23ba9401352f30d5af8f4eccb (patch) | |
tree | f26452d06cffb42d2ecbab653a267a1a8834e445 /src | |
parent | 83421e320b8b0b2ddd528a280609cbb7f2cb7781 (diff) |
Simplify QDateTimeParser::fromString() to always record the date-time
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 <marten.nordheim@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/time/qdatetimeparser.cpp | 12 |
1 files 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 |