Skip to content

Commit

Permalink
locale: Fix 24 hour format for DateTimeFormats.
Browse files Browse the repository at this point in the history
Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
Fixes #12575. I checked with PulkoMandy on IRC before merging this,
and fixed some whitespace violations of the coding style.
  • Loading branch information
markhellegers authored and waddlesplash committed Jun 18, 2016
1 parent 8981510 commit ac315db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
1 change: 1 addition & 0 deletions headers/os/locale/FormattingConventions.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class BFormattingConventions : public BArchivable {
bool fUseStringsFromPreferredLanguage;

U_ICU_NAMESPACE::Locale* fICULocale;
void CoerceFormatForClock(BString& outFormat) const;
};


Expand Down
41 changes: 28 additions & 13 deletions src/kits/locale/FormattingConventions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit ac315db

Please sign in to comment.