From 0df8e70fbde912b7ee6a594112c13221ea338f72 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 26 Aug 2020 14:13:08 +0200 Subject: macOS: fix standaloneMonthName implementation for system locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS has specific formatters for the standalone month names, so use them. Change-Id: Ic4ad547c7d1c29d71c85f60301acd5a5f0f263d2 Fixes: QTBUG-86191 Reviewed-by: Tor Arne Vestbø Reviewed-by: Evgeniy Dushistov Reviewed-by: Edward Welbourne (cherry picked from commit 062d2831845eb07518d7c059b155a640bd0300f3) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qlocale_mac.mm | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/corelib/text') diff --git a/src/corelib/text/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm index 5381f0f975..0c60b94254 100644 --- a/src/corelib/text/qlocale_mac.mm +++ b/src/corelib/text/qlocale_mac.mm @@ -81,7 +81,7 @@ static QString getMacLocaleName() return result; } -static QString macMonthName(int month, bool short_format) +static QString macMonthName(int month, QSystemLocale::QueryType type) { month -= 1; if (month < 0 || month > 11) @@ -90,10 +90,28 @@ static QString macMonthName(int month, bool short_format) QCFType formatter = CFDateFormatterCreate(0, QCFType(CFLocaleCopyCurrent()), kCFDateFormatterNoStyle, kCFDateFormatterNoStyle); + + CFDateFormatterKey formatterType; + switch (type) { + case QSystemLocale::MonthNameLong: + formatterType = kCFDateFormatterMonthSymbols; + break; + case QSystemLocale::MonthNameShort: + formatterType = kCFDateFormatterShortMonthSymbols; + break; + case QSystemLocale::StandaloneMonthNameLong: + formatterType = kCFDateFormatterStandaloneMonthSymbols; + break; + case QSystemLocale::StandaloneMonthNameShort: + formatterType = kCFDateFormatterShortStandaloneMonthSymbols; + break; + default: + qWarning("macMonthName: Unsupported query type %d", type); + return QString(); + } QCFType values - = static_cast(CFDateFormatterCopyProperty(formatter, - short_format ? kCFDateFormatterShortMonthSymbols - : kCFDateFormatterMonthSymbols)); + = static_cast(CFDateFormatterCopyProperty(formatter, formatterType)); + if (values != 0) { CFStringRef cfstring = static_cast(CFArrayGetValueAtIndex(values, month)); return QString::fromCFString(cfstring); @@ -434,7 +452,7 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const case MonthNameShort: case StandaloneMonthNameLong: case StandaloneMonthNameShort: - return macMonthName(in.toInt(), (type == MonthNameShort || type == StandaloneMonthNameShort)); + return macMonthName(in.toInt(), type); case DateToStringShort: case DateToStringLong: return macDateToString(in.toDate(), (type == DateToStringShort)); -- cgit v1.2.3