diff options
Diffstat (limited to 'src/corelib/tools/qdatetimeparser.cpp')
-rw-r--r-- | src/corelib/tools/qdatetimeparser.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index 1a56418aaf..551e01e076 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -802,6 +802,7 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, break; } Q_FALLTHROUGH(); + // All numeric: case DaySection: case YearSection: case YearSection2Digits: @@ -824,9 +825,9 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, bool ok = true; int last = -1, used = -1; - const int max = qMin(sectionmaxsize, sectiontextSize); - QStringRef digitsStr = sectionTextRef.left(max); - for (int digits = max; digits >= 1; --digits) { + Q_ASSERT(sectiontextSize <= sectionmaxsize); + QStringRef digitsStr = sectionTextRef.left(sectiontextSize); + for (int digits = sectiontextSize; digits >= 1; --digits) { digitsStr.truncate(digits); int tmp = (int)loc.toUInt(digitsStr, &ok); if (ok && sn.type == Hour12Section) { @@ -853,20 +854,20 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, QDTPDEBUG << "invalid because" << sectionTextRef << "can't become a uint" << last << ok; } else { const FieldInfo fi = fieldInfo(sectionIndex); - const bool done = (used == sectionmaxsize); - if (!done && fi & Fraction) { // typing 2 in a zzz field should be .200, not .002 + const bool unfilled = used < sectionmaxsize; + if (unfilled && fi & Fraction) { // typing 2 in a zzz field should be .200, not .002 for (int i = used; i < sectionmaxsize; ++i) last *= 10; } + // Even those *= 10s can't take last above absMax: + Q_ASSERT(last <= absMax); const int absMin = absoluteMin(sectionIndex); if (last < absMin) { - if (!done) // reversed test to dodge QDTPDEBUG ugliness ! + if (unfilled) result = ParsedSection(Intermediate, last, used); else QDTPDEBUG << "invalid because" << last << "is less than absoluteMin" << absMin; - } else if (last > absMax) { - result = ParsedSection(Intermediate, last, used); - } else if (!done && (fi & (FixedWidth|Numeric)) == (FixedWidth|Numeric)) { + } else if (unfilled && (fi & (FixedWidth|Numeric)) == (FixedWidth|Numeric)) { if (skipToNextSection(sectionIndex, currentValue, digitsStr)) { const int missingZeroes = sectionmaxsize - digitsStr.size(); result = ParsedSection(Acceptable, last, sectionmaxsize, missingZeroes); @@ -1159,7 +1160,8 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, } state = qMin<State>(state, sect.state); - if (state == Invalid || (state == Intermediate && context == FromString)) + // QDateTimeEdit can fix Intermediate and zeroes, but input needing that didn't match format: + if (state == Invalid || (context == FromString && (state == Intermediate || sect.zeroes))) return StateNode(); switch (sn.type) { @@ -1475,8 +1477,8 @@ QDateTimeParser::parse(QString input, int position, const QDateTime &defaultValu } else { if (context == FromString) { // optimization - Q_ASSERT(maximum.date().toJulianDay() == 4642999); - if (scan.value.date().toJulianDay() > 4642999) + Q_ASSERT(maximum.date().toJulianDay() == 5373484); + if (scan.value.date().toJulianDay() > 5373484) scan.state = Invalid; } else { if (scan.value > maximum) |