summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qdatetimeedit.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-02-28 08:40:53 +0100
committerLars Knoll <lars.knoll@qt.io>2020-02-28 09:48:30 +0100
commita450cce6b670dbcac84fcc4a66fc632b31ce8414 (patch)
tree35b77fa22c4def97b619bd3a87f6d394e452bb2e /src/widgets/widgets/qdatetimeedit.cpp
parentf6f6eab89f57fb0db8f623f4a92a7b9c4ba6e9ea (diff)
parent4c86e667d220e27bb4b6e370675ffb2872e8521c (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'src/widgets/widgets/qdatetimeedit.cpp')
-rw-r--r--src/widgets/widgets/qdatetimeedit.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp
index 48588b1e8e..105318ba20 100644
--- a/src/widgets/widgets/qdatetimeedit.cpp
+++ b/src/widgets/widgets/qdatetimeedit.cpp
@@ -683,7 +683,8 @@ void QDateTimeEdit::setTimeRange(QTime min, QTime max)
\brief The currently displayed fields of the date time edit.
Returns a bit set of the displayed sections for this format.
- \a setDisplayFormat(), displayFormat()
+
+ \sa setDisplayFormat(), displayFormat()
*/
QDateTimeEdit::Sections QDateTimeEdit::displayedSections() const
@@ -696,7 +697,8 @@ QDateTimeEdit::Sections QDateTimeEdit::displayedSections() const
\property QDateTimeEdit::currentSection
\brief The current section of the spinbox.
- \a setCurrentSection()
+
+ \sa setCurrentSection()
*/
QDateTimeEdit::Section QDateTimeEdit::currentSection() const
@@ -776,8 +778,7 @@ int QDateTimeEdit::sectionCount() const
the cursorPosition is 5, currentSectionIndex returns 1. If the
cursorPosition is 3, currentSectionIndex is 0, and so on.
- \a setCurrentSection()
- \sa currentSection()
+ \sa setCurrentSection(), currentSection()
*/
int QDateTimeEdit::currentSectionIndex() const
@@ -1448,7 +1449,16 @@ void QDateTimeEdit::fixup(QString &input) const
QValidator::State state;
int copy = d->edit->cursorPosition();
- d->validateAndInterpret(input, copy, state, true);
+ QDateTime value = d->validateAndInterpret(input, copy, state, true);
+ /*
+ String was valid, but the datetime still is not; use the time that
+ has the same distance from epoch.
+ CorrectToPreviousValue correction is handled by QAbstractSpinBox.
+ */
+ if (!value.isValid() && d->correctionMode == QAbstractSpinBox::CorrectToNearestValue) {
+ value = QDateTime::fromMSecsSinceEpoch(value.toMSecsSinceEpoch(), value.timeSpec());
+ input = textFromDateTime(value);
+ }
}
@@ -2085,6 +2095,17 @@ QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) c
const int oldDay = v.date().day(calendar);
setDigit(v, sectionIndex, val);
+ /*
+ Stepping into a daylight saving time that doesn't exist,
+ so use the time that has the same distance from epoch.
+ */
+ if (!v.isValid()) {
+ auto msecsSinceEpoch = v.toMSecsSinceEpoch();
+ // decreasing from e.g 3am to 2am would get us back to 3am, but we want 1am
+ if (steps < 0 && sn.type & HourSectionMask)
+ msecsSinceEpoch -= 3600 * 1000;
+ v = QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch, v.timeSpec());
+ }
// if this sets year or month it will make
// sure that days are lowered if needed.