From 7605c476769f65f95f65c6dda5f48e4eccbf69b0 Mon Sep 17 00:00:00 2001
From: Mark Hellegers <mark@firedisk.net>
Date: Sun, 29 May 2016 15:00:00 +0000
Subject: [PATCH] Fix 24 hour format for DateTimeFormats
---
headers/os/locale/FormattingConventions.h | 1 +
src/kits/locale/FormattingConventions.cpp | 41 ++++++++++++++++++++-----------
2 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/headers/os/locale/FormattingConventions.h b/headers/os/locale/FormattingConventions.h
index 9a888f8..607400d 100644
a
|
b
|
private:
|
141 | 141 | bool fUseStringsFromPreferredLanguage; |
142 | 142 | |
143 | 143 | U_ICU_NAMESPACE::Locale* fICULocale; |
| 144 | void CoerceFormatForClock(BString& outFormat) const; |
144 | 145 | }; |
145 | 146 | |
146 | 147 | |
diff --git a/src/kits/locale/FormattingConventions.cpp b/src/kits/locale/FormattingConventions.cpp
index 0ae512f..de617e7 100644
a
|
b
|
BFormattingConventions::GetDateFormat(BDateFormatStyle style,
|
447 | 447 | return B_OK; |
448 | 448 | } |
449 | 449 | |
450 | | |
451 | 450 | status_t |
452 | 451 | BFormattingConventions::GetTimeFormat(BTimeFormatStyle style, |
453 | 452 | BString& outFormat) const |
… |
… |
BFormattingConventions::GetTimeFormat(BTimeFormatStyle style,
|
475 | 474 | BStringByteSink stringConverter(&outFormat); |
476 | 475 | icuString.toUTF8(stringConverter); |
477 | 476 | |
478 | | int8 use24HourClock = fExplicitUse24HourClock != CLOCK_HOURS_UNSET |
479 | | ? fExplicitUse24HourClock : fCachedUse24HourClock; |
480 | | if (use24HourClock != CLOCK_HOURS_UNSET) { |
481 | | // adjust to 12/24-hour clock as requested |
482 | | bool localeUses24HourClock = !FormatUsesAmPm(outFormat); |
483 | | if (localeUses24HourClock) { |
484 | | if (use24HourClock == CLOCK_HOURS_12) |
485 | | CoerceFormatTo12HourClock(outFormat); |
486 | | } else { |
487 | | if (use24HourClock == CLOCK_HOURS_24) |
488 | | CoerceFormatTo24HourClock(outFormat); |
489 | | } |
490 | | } |
| 477 | CoerceFormatForClock(outFormat); |
491 | 478 | |
492 | 479 | if (style != B_FULL_TIME_FORMAT) { |
493 | 480 | // use abbreviated timezone in short timezone format |
… |
… |
BFormattingConventions::GetDateTimeFormat(BDateFormatStyle dateStyle,
|
531 | 518 | BStringByteSink stringConverter(&outFormat); |
532 | 519 | icuString.toUTF8(stringConverter); |
533 | 520 | |
| 521 | CoerceFormatForClock(outFormat); |
| 522 | |
| 523 | if (dateStyle != B_FULL_DATE_FORMAT) { |
| 524 | // use abbreviated timezone in short timezone format |
| 525 | CoerceFormatToAbbreviatedTimezone(outFormat); |
| 526 | } |
| 527 | |
534 | 528 | fCachedDateTimeFormats[dateStyle][timeStyle] = outFormat; |
535 | 529 | |
536 | 530 | return B_OK; |
… |
… |
BFormattingConventions::Archive(BMessage* archive, bool deep) const
|
665 | 659 | |
666 | 660 | return status; |
667 | 661 | } |
| 662 | |
| 663 | void |
| 664 | BFormattingConventions::CoerceFormatForClock(BString& outFormat) const |
| 665 | { |
| 666 | int8 use24HourClock = fExplicitUse24HourClock != CLOCK_HOURS_UNSET |
| 667 | ? fExplicitUse24HourClock : fCachedUse24HourClock; |
| 668 | if (use24HourClock != CLOCK_HOURS_UNSET) { |
| 669 | // adjust to 12/24-hour clock as requested |
| 670 | bool localeUses24HourClock = !FormatUsesAmPm(outFormat); |
| 671 | if (localeUses24HourClock) { |
| 672 | if (use24HourClock == CLOCK_HOURS_12) |
| 673 | CoerceFormatTo12HourClock(outFormat); |
| 674 | } else { |
| 675 | if (use24HourClock == CLOCK_HOURS_24) |
| 676 | CoerceFormatTo24HourClock(outFormat); |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |