From 903903147924641a84e62432037b006c6bf541b7 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 29 Aug 2012 12:58:35 +0200 Subject: Fix QDateEdit displaying day as a number for short and long day formats When 2 (February) is entered as the month for (e.g.) 31/Jan/2000 (which is following the format: "dd/MMM/yyyy"), the day is corrected to 29 but displayed as its numerical value instead of its short (or long) name. Task-number: QTBUG-27036 QTBUG-19091 Change-Id: I558ee13b224707d22b26c2ec2c045f96118bd5a1 Reviewed-by: Mitch Curtis Reviewed-by: aavit --- src/corelib/tools/qdatetime.cpp | 56 ++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'src/corelib/tools/qdatetime.cpp') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 421e6db81e..cbbf31b36f 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -4188,7 +4188,8 @@ int QDateTimeParser::getDigit(const QDateTime &t, int index) const case YearSection: return t.date().year(); case MonthSection: return t.date().month(); case DaySection: return t.date().day(); - case DayOfWeekSection: return t.date().day(); + case DayOfWeekSectionShort: + case DayOfWeekSectionLong: return t.date().day(); case AmPmSection: return t.time().hour() > 11 ? 1 : 0; default: break; @@ -4246,7 +4247,8 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const case YearSection: year = newVal; break; case MonthSection: month = newVal; break; case DaySection: - case DayOfWeekSection: + case DayOfWeekSectionShort: + case DayOfWeekSectionLong: if (newVal > 31) { // have to keep legacy behavior. setting the // date to 32 should return false. Setting it @@ -4262,7 +4264,7 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const break; } - if (!(node.type & (DaySection|DayOfWeekSection))) { + if (!(node.type & (DaySection|DayOfWeekSectionShort|DayOfWeekSectionLong))) { if (day < cachedDay) day = cachedDay; const int max = QDate(year, month, 1).daysInMonth(); @@ -4303,7 +4305,8 @@ int QDateTimeParser::absoluteMax(int s, const QDateTime &cur) const // stepBy() will work on real years anyway case MonthSection: return 12; case DaySection: - case DayOfWeekSection: return cur.isValid() ? cur.date().daysInMonth() : 31; + case DayOfWeekSectionShort: + case DayOfWeekSectionLong: return cur.isValid() ? cur.date().daysInMonth() : 31; case AmPmSection: return 1; default: break; } @@ -4331,7 +4334,8 @@ int QDateTimeParser::absoluteMin(int s) const case YearSection: return 0; case MonthSection: case DaySection: - case DayOfWeekSection: return 1; + case DayOfWeekSectionShort: + case DayOfWeekSectionLong: return 1; case AmPmSection: return 0; default: break; } @@ -4573,7 +4577,9 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) case 'd': if (parserType != QVariant::Time) { const int repeat = countRepeat(newFormat, i, 4); - const SectionNode sn = { repeat >= 3 ? DayOfWeekSection : DaySection, i - add, repeat, 0 }; + const Section sectionType = (repeat == 4 ? DayOfWeekSectionLong + : (repeat == 3 ? DayOfWeekSectionShort : DaySection)); + const SectionNode sn = { sectionType, i - add, repeat, 0 }; newSectionNodes.append(sn); appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); i += sn.count - 1; @@ -4688,7 +4694,8 @@ int QDateTimeParser::sectionMaxSize(Section s, int count) const case MinuteSection: case SecondSection: case DaySection: return 2; - case DayOfWeekSection: + case DayOfWeekSectionShort: + case DayOfWeekSectionLong: #ifdef QT_NO_TEXTDATE return 2; #else @@ -4843,7 +4850,8 @@ int QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionInde } break; } case MonthSection: - case DayOfWeekSection: + case DayOfWeekSectionShort: + case DayOfWeekSectionLong: if (sn.count >= 3) { if (sn.type == MonthSection) { int min = 1; @@ -5049,7 +5057,8 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos case YearSection: current = &year; break; case YearSection2Digits: current = &year2digits; break; case MonthSection: current = &month; break; - case DayOfWeekSection: current = &dayofweek; break; + case DayOfWeekSectionShort: + case DayOfWeekSectionLong: current = &dayofweek; break; case DaySection: current = &day; num = qMax(1, num); break; case AmPmSection: current = &m; break; default: @@ -5103,10 +5112,10 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos const QDate date(year, month, day); const int diff = dayofweek - date.dayOfWeek(); - if (diff != 0 && state == Acceptable && isSet & DayOfWeekSection) { + if (diff != 0 && state == Acceptable && isSet & (DayOfWeekSectionShort|DayOfWeekSectionLong)) { conflicts = isSet & DaySection; const SectionNode &sn = sectionNode(currentSectionIndex); - if (sn.type == DayOfWeekSection || currentSectionIndex == -1) { + if (sn.type & (DayOfWeekSectionShort|DayOfWeekSectionLong) || currentSectionIndex == -1) { // dayofweek should be preferred day += diff; if (day <= 0) { @@ -5119,7 +5128,7 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos } } bool needfixday = false; - if (sectionType(currentSectionIndex) & (DaySection|DayOfWeekSection)) { + if (sectionType(currentSectionIndex) & (DaySection|DayOfWeekSectionShort|DayOfWeekSectionLong)) { cachedDay = day; } else if (cachedDay > day) { day = cachedDay; @@ -5144,8 +5153,15 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos const QLocale loc = locale(); for (int i=0; i