summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qdatetimeedit.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-11-15 17:59:18 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2018-11-27 14:23:25 +0000
commit4e01b851159342122d42be1091d4cfa464700a4e (patch)
treeca231f1de255ddd4251801c5a26525882ccdb56c /src/widgets/widgets/qdatetimeedit.cpp
parentd41879db384905c47c8fca976ae70ad6595de41f (diff)
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>
Diffstat (limited to 'src/widgets/widgets/qdatetimeedit.cpp')
-rw-r--r--src/widgets/widgets/qdatetimeedit.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp
index fca81bec48..68bfd175ff 100644
--- a/src/widgets/widgets/qdatetimeedit.cpp
+++ b/src/widgets/widgets/qdatetimeedit.cpp
@@ -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();
}
}