From ac315db012d8ecde27f8e6969fa871c9842ca67c Mon Sep 17 00:00:00 2001 From: Mark Hellegers Date: Sun, 29 May 2016 15:00:00 +0000 Subject: [PATCH] locale: Fix 24 hour format for DateTimeFormats. Signed-off-by: Augustin Cavalier Fixes #12575. I checked with PulkoMandy on IRC before merging this, and fixed some whitespace violations of the coding style. --- headers/os/locale/FormattingConventions.h | 1 + src/kits/locale/FormattingConventions.cpp | 41 ++++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/headers/os/locale/FormattingConventions.h b/headers/os/locale/FormattingConventions.h index 9a888f8aac..607400d86f 100644 --- a/headers/os/locale/FormattingConventions.h +++ b/headers/os/locale/FormattingConventions.h @@ -141,6 +141,7 @@ private: bool fUseStringsFromPreferredLanguage; U_ICU_NAMESPACE::Locale* fICULocale; + void CoerceFormatForClock(BString& outFormat) const; }; diff --git a/src/kits/locale/FormattingConventions.cpp b/src/kits/locale/FormattingConventions.cpp index 0ae512fee5..2c6a20da6e 100644 --- a/src/kits/locale/FormattingConventions.cpp +++ b/src/kits/locale/FormattingConventions.cpp @@ -475,19 +475,7 @@ BFormattingConventions::GetTimeFormat(BTimeFormatStyle style, BStringByteSink stringConverter(&outFormat); icuString.toUTF8(stringConverter); - int8 use24HourClock = fExplicitUse24HourClock != CLOCK_HOURS_UNSET - ? fExplicitUse24HourClock : fCachedUse24HourClock; - if (use24HourClock != CLOCK_HOURS_UNSET) { - // adjust to 12/24-hour clock as requested - bool localeUses24HourClock = !FormatUsesAmPm(outFormat); - if (localeUses24HourClock) { - if (use24HourClock == CLOCK_HOURS_12) - CoerceFormatTo12HourClock(outFormat); - } else { - if (use24HourClock == CLOCK_HOURS_24) - CoerceFormatTo24HourClock(outFormat); - } - } + CoerceFormatForClock(outFormat); if (style != B_FULL_TIME_FORMAT) { // use abbreviated timezone in short timezone format @@ -531,6 +519,13 @@ BFormattingConventions::GetDateTimeFormat(BDateFormatStyle dateStyle, BStringByteSink stringConverter(&outFormat); icuString.toUTF8(stringConverter); + CoerceFormatForClock(outFormat); + + if (dateStyle != B_FULL_DATE_FORMAT) { + // use abbreviated timezone in short timezone format + CoerceFormatToAbbreviatedTimezone(outFormat); + } + fCachedDateTimeFormats[dateStyle][timeStyle] = outFormat; return B_OK; @@ -665,3 +660,23 @@ BFormattingConventions::Archive(BMessage* archive, bool deep) const return status; } + + +void +BFormattingConventions::CoerceFormatForClock(BString& outFormat) const +{ + int8 use24HourClock = fExplicitUse24HourClock != CLOCK_HOURS_UNSET + ? fExplicitUse24HourClock : fCachedUse24HourClock; + if (use24HourClock != CLOCK_HOURS_UNSET) { + // adjust to 12/24-hour clock as requested + bool localeUses24HourClock = !FormatUsesAmPm(outFormat); + if (localeUses24HourClock) { + if (use24HourClock == CLOCK_HOURS_12) + CoerceFormatTo12HourClock(outFormat); + } else { + if (use24HourClock == CLOCK_HOURS_24) + CoerceFormatTo24HourClock(outFormat); + } + } +} +