Fix initialization of QDateEdit and QTimeEdit

Since 6.3 these use Qt::UTC as time-spec but I neglected to take that
into account in QDateTimeEditPrivate::init()'s construction of a
QDateTime from the QDate or QTime. This amends
commit c00ee2f310.

Fixes: QTBUG-105322
Pick-to: 6.3 6.4
Change-Id: I11dec9808a54cf7da401b1734a9a2812f5fd2e63
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2022-08-03 14:11:18 +02:00
parent a46a426b43
commit 607c5a90c5
2 changed files with 2 additions and 4 deletions

View File

@ -2480,7 +2480,7 @@ void QDateTimeEditPrivate::init(const QVariant &var)
Q_Q(QDateTimeEdit);
switch (var.userType()) {
case QMetaType::QDate:
value = var.toDate().startOfDay();
value = var.toDate().startOfDay(spec);
updateTimeSpec();
q->setDisplayFormat(defaultDateFormat);
if (sectionNodes.isEmpty()) // ### safeguard for broken locale
@ -2494,7 +2494,7 @@ void QDateTimeEditPrivate::init(const QVariant &var)
q->setDisplayFormat("dd/MM/yyyy hh:mm:ss"_L1);
break;
case QMetaType::QTime:
value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime());
value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime(), spec);
updateTimeSpec();
q->setDisplayFormat(defaultTimeFormat);
if (sectionNodes.isEmpty()) // ### safeguard for broken locale

View File

@ -506,7 +506,6 @@ void tst_QDateTimeEdit::constructor_qdate()
{
QDateEdit dte(parameter);
dte.show();
QEXPECT_FAIL("", "QTBUG-105322: constructors use wrong spec", Continue);
if (QByteArrayView(QTest::currentDataTag()) == "invalid")
QCOMPARE(dte.date(), QDate(2000, 1, 1));
else
@ -546,7 +545,6 @@ void tst_QDateTimeEdit::constructor_qtime()
{
QTimeEdit dte(parameter);
dte.show();
QEXPECT_FAIL("", "QTBUG-105322: constructors use wrong spec", Abort);
if (QByteArrayView(QTest::currentDataTag()) == "invalid")
QCOMPARE(dte.time(), QTime(0, 0));
else