summaryrefslogtreecommitdiffstats
path: root/src/corelib/time
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-11-24 17:32:50 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2020-11-27 13:26:53 +0100
commitcdcfb7c4f905fd75887d9f7aa5646dd91edde3ab (patch)
tree17b26b7d1bda7fd406e90448a7a38cb79f7e339a /src/corelib/time
parent380d97e1bd15e753907c378a070bdf7f1c1cf06e (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time')
-rw-r--r--src/corelib/time/qdatetimeparser.cpp18
1 files 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;