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 <thiago.macieira@intel.com>
bb10
Edward Welbourne 2023-04-25 13:37:30 +02:00
parent 4c93b9c1d0
commit 7d75039482
1 changed files with 2 additions and 2 deletions

View File

@ -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();