From cdcfb7c4f905fd75887d9f7aa5646dd91edde3ab Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 24 Nov 2020 17:32:50 +0100 Subject: [PATCH] QDateTimeParser: fix handling of AM/PM texts An AM/PM field is only fixed-width if the locale's AM and PM texts have the same length, which we shouldn't take for granted. (They're not in Albanian, Bosnian or Cherokee.) In sectionMaxSize(), count tells us the case, so we shouldn't be taking both case variants into account, only the one we need. Change-Id: I03b985cc5bf74c34742480558cef08af6343ed93 Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetimeparser.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index a36eded2e5..c64f622a57 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -640,13 +640,10 @@ int QDateTimeParser::sectionMaxSize(Section s, int count) const case LastSection: return 0; - case AmPmSection: { - const int lowerMax = qMax(getAmPmText(AmText, LowerCase).size(), - getAmPmText(PmText, LowerCase).size()); - const int upperMax = qMax(getAmPmText(AmText, UpperCase).size(), - getAmPmText(PmText, UpperCase).size()); - return qMax(lowerMax, upperMax); - } + case AmPmSection: + // Special: "count" here is a case flag, not field width ! + return qMax(getAmPmText(AmText, count ? UpperCase : LowerCase).size(), + getAmPmText(PmText, count ? UpperCase : LowerCase).size()); case Hour24Section: case Hour12Section: @@ -1937,7 +1934,12 @@ QDateTimeParser::FieldInfo QDateTimeParser::fieldInfo(int index) const ret |= FixedWidth; break; case AmPmSection: - ret |= FixedWidth; + // Some locales have different length AM and PM texts. + if (getAmPmText(AmText, sn.count ? UpperCase : LowerCase).size() + == getAmPmText(PmText, sn.count ? UpperCase : LowerCase).size()) { + // Only relevant to DateTimeEdit's fixups in parse(). + ret |= FixedWidth; + } break; case TimeZoneSection: break;