QDateTimeEdit: fix setDate() if time is in a spring-forward
If the time the widget is set to use falls in the gap skipped by a spring-forward, setting the date to the day of the spring-forward turned a valid date into an invalid date-time. So use the usual trick to map the "draft" date-time to a valid one. Fixes: QTBUG-64485 Fixes: QTBUG-58947 Change-Id: Ib8f0f092cd5d6dce3da31eb52cd42150ca0d1fcb Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>bb10
parent
d41879db38
commit
4e01b85115
|
|
@ -273,7 +273,13 @@ void QDateTimeEdit::setDate(const QDate &date)
|
|||
setDateRange(date, date);
|
||||
|
||||
d->clearCache();
|
||||
d->setValue(QDateTime(date, d->value.toTime(), d->spec), EmitIfChanged);
|
||||
QDateTime when(date, d->value.toTime(), d->spec);
|
||||
// The specified time might not exist on the specified day,
|
||||
// i.e. the time is in the gap a spring-forward jumps over.
|
||||
if (!when.isValid())
|
||||
when = QDateTime::fromMSecsSinceEpoch(when.toMSecsSinceEpoch(), d->spec);
|
||||
Q_ASSERT(when.isValid());
|
||||
d->setValue(when, EmitIfChanged);
|
||||
d->updateTimeSpec();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue