status_t BFormattingConventions::GetTimeFormat(BTimeFormatStyle style, BString& outFormat) const { if (style < 0 || style >= B_TIME_FORMAT_STYLE_COUNT) return B_BAD_VALUE; outFormat = fExplicitTimeFormats[style].Length() ? fExplicitTimeFormats[style] : fCachedTimeFormats[style]; if (outFormat.Length() > 0) return B_OK; ObjectDeleter<DateFormat> timeFormatter( DateFormat::createTimeInstance((DateFormat::EStyle)style, *fICULocale)); if (timeFormatter.Get() == NULL) return B_NO_MEMORY; SimpleDateFormat* timeFormatterImpl = static_cast<SimpleDateFormat*>(timeFormatter.Get()); UnicodeString icuString; timeFormatterImpl->toPattern(icuString); 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); } } // use abbreviated timezone in short timezone format CoerceFormatToAbbreviatedTimezone(outFormat); fCachedTimeFormats[style] = outFormat; return B_OK; }
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); } } }