summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-08-06 12:24:37 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-08-27 20:31:18 +0200
commitd95f4d00189082e0217ab06aa0911e6bbffb3ade (patch)
tree44cdf890b34b0cb015aac916de714a00b57b82bb
parent17d7a8dc2e2df577a769cd84cba946a726e8872a (diff)
qlocale_win: Simplify and explain month-name format lookup
Retain the given month number and simply subtract one from it in the one place it's used (once the two array dereferencs are unified). That makes it clear that the off-by-one numbering is just down to our arrays, not some weired quirk of the MS API. Simplify a condition by inverting it: compare to LongFormat instead of ||-ing comparisons to the other two members of the enum. Change-Id: Ia03486b7869255ecdb1372de62d5c745d35d0a0a Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/text/qlocale_win.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp
index 38f04d686d..bfb20538eb 100644
--- a/src/corelib/text/qlocale_win.cpp
+++ b/src/corelib/text/qlocale_win.cpp
@@ -380,13 +380,12 @@ QVariant QSystemLocalePrivate::monthName(int month, QLocale::FormatType type)
LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,
LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12 };
- month -= 1;
- if (month < 0 || month > 11)
+ if (month < 1 || month > 12)
return {};
- LCTYPE lctype = (type == QLocale::ShortFormat || type == QLocale::NarrowFormat)
- ? short_month_map[month] : long_month_map[month];
- return getLocaleInfo(lctype);
+ // Month is Jan = 1, ... Dec = 12; adjust by 1 to match array indexing from 0:
+ return getLocaleInfo(
+ (type == QLocale::LongFormat ? long_month_map : short_month_map)[month - 1]);
}
QVariant QSystemLocalePrivate::toString(QDate date, QLocale::FormatType type)