locale: Fix 24 hour format for DateTimeFormats.
Signed-off-by: Augustin Cavalier <[email protected]> Fixes #12575. I checked with PulkoMandy on IRC before merging this, and fixed some whitespace violations of the coding style.
This commit is contained in:
committed by
Augustin Cavalier
parent
8981510671
commit
ac315db012
@@ -141,6 +141,7 @@ private:
|
|||||||
bool fUseStringsFromPreferredLanguage;
|
bool fUseStringsFromPreferredLanguage;
|
||||||
|
|
||||||
U_ICU_NAMESPACE::Locale* fICULocale;
|
U_ICU_NAMESPACE::Locale* fICULocale;
|
||||||
|
void CoerceFormatForClock(BString& outFormat) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -475,19 +475,7 @@ BFormattingConventions::GetTimeFormat(BTimeFormatStyle style,
|
|||||||
BStringByteSink stringConverter(&outFormat);
|
BStringByteSink stringConverter(&outFormat);
|
||||||
icuString.toUTF8(stringConverter);
|
icuString.toUTF8(stringConverter);
|
||||||
|
|
||||||
int8 use24HourClock = fExplicitUse24HourClock != CLOCK_HOURS_UNSET
|
CoerceFormatForClock(outFormat);
|
||||||
? 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (style != B_FULL_TIME_FORMAT) {
|
if (style != B_FULL_TIME_FORMAT) {
|
||||||
// use abbreviated timezone in short timezone format
|
// use abbreviated timezone in short timezone format
|
||||||
@@ -531,6 +519,13 @@ BFormattingConventions::GetDateTimeFormat(BDateFormatStyle dateStyle,
|
|||||||
BStringByteSink stringConverter(&outFormat);
|
BStringByteSink stringConverter(&outFormat);
|
||||||
icuString.toUTF8(stringConverter);
|
icuString.toUTF8(stringConverter);
|
||||||
|
|
||||||
|
CoerceFormatForClock(outFormat);
|
||||||
|
|
||||||
|
if (dateStyle != B_FULL_DATE_FORMAT) {
|
||||||
|
// use abbreviated timezone in short timezone format
|
||||||
|
CoerceFormatToAbbreviatedTimezone(outFormat);
|
||||||
|
}
|
||||||
|
|
||||||
fCachedDateTimeFormats[dateStyle][timeStyle] = outFormat;
|
fCachedDateTimeFormats[dateStyle][timeStyle] = outFormat;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -665,3 +660,23 @@ BFormattingConventions::Archive(BMessage* archive, bool deep) const
|
|||||||
|
|
||||||
return status;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user