From 7d7503948274e9cacdf3a7cea011ff8a5103bfa1 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 25 Apr 2023 13:37:30 +0200 Subject: [PATCH] Make default local time a static const QDateTimeParser::fromString(), when parsing a date-time, uses the start of 1900, in local time, as its default date-time. (This is a bad choice and steadily getting worse.) This turns out to be somewhat expensive for some client code, so make it a static const so that we only compute it on the first call, as for getM{in,ax}imum(). The potential downside is that a change to system time zone won't be reflected in this value. However, any sane parse-format should require over-writing all fields of this initial value, in any case, so the issue is less severe for this default value than for the existing getM{in,ax}imum() statics. Change-Id: Iacfd827fe76c4e5fbdc5e5b6efefed13bc673af4 Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetimeparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index aff78eae2f..3b1df46c60 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -2186,8 +2186,8 @@ bool QDateTimeParser::fromString(const QString &t, QDate *date, QTime *time) con // Only called when we want both date and time; default to local time. bool QDateTimeParser::fromString(const QString &t, QDateTime *datetime) const { - QDateTime val(QDate(1900, 1, 1).startOfDay()); - const StateNode tmp = parse(t, -1, val, false); + static const QDateTime defaultLocalTime = QDate(1900, 1, 1).startOfDay(); + const StateNode tmp = parse(t, -1, defaultLocalTime, false); if (datetime) *datetime = tmp.value; return tmp.state == Acceptable && !tmp.conflicts && tmp.value.isValid();