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>bb10
parent
83421e320b
commit
b4ee126a75
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue