Skip to content

Commit 611e412

Browse files
FrankYFTangCommit Bot
authored andcommitted
[Intl] Use new getDefaultHourCycle to replace old hack
Use the ICU 67.1 new API DateTimePatternGenerator::getDefaultHourCycle to replace a hack which get the pattern of "jjmm" to find out the default hour cycle of a locale Bump the required API version from 65 to 67 Bug: v8:10225 Change-Id: I3378edacb6dfb8400357ac0bf3d5d50b9fe008bd Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2173875 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/master@{#67549}
1 parent 1faa8c8 commit 611e412

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/objects/intl-objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "unicode/locid.h"
2222
#include "unicode/uversion.h"
2323

24-
#define V8_MINIMUM_ICU_VERSION 65
24+
#define V8_MINIMUM_ICU_VERSION 67
2525

2626
namespace U_ICU_NAMESPACE {
2727
class BreakIterator;

src/objects/js-date-time-format.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ JSDateTimeFormat::HourCycle ToHourCycle(const std::string& hc) {
4242
return JSDateTimeFormat::HourCycle::kUndefined;
4343
}
4444

45+
JSDateTimeFormat::HourCycle ToHourCycle(UDateFormatHourCycle hc) {
46+
switch (hc) {
47+
case UDAT_HOUR_CYCLE_11:
48+
return JSDateTimeFormat::HourCycle::kH11;
49+
case UDAT_HOUR_CYCLE_12:
50+
return JSDateTimeFormat::HourCycle::kH12;
51+
case UDAT_HOUR_CYCLE_23:
52+
return JSDateTimeFormat::HourCycle::kH23;
53+
case UDAT_HOUR_CYCLE_24:
54+
return JSDateTimeFormat::HourCycle::kH24;
55+
default:
56+
return JSDateTimeFormat::HourCycle::kUndefined;
57+
}
58+
}
59+
4560
Maybe<JSDateTimeFormat::HourCycle> GetHourCycle(Isolate* isolate,
4661
Handle<JSReceiver> options,
4762
const char* method) {
@@ -1518,9 +1533,8 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
15181533
generator_cache.Pointer()->CreateGenerator(icu_locale));
15191534

15201535
// 15.Let hcDefault be dataLocaleData.[[hourCycle]].
1521-
icu::UnicodeString hour_pattern = generator->getBestPattern("jjmm", status);
1536+
HourCycle hc_default = ToHourCycle(generator->getDefaultHourCycle(status));
15221537
CHECK(U_SUCCESS(status));
1523-
HourCycle hc_default = HourCycleFromPattern(hour_pattern);
15241538

15251539
// 16.Let hc be r.[[hc]].
15261540
HourCycle hc = HourCycle::kUndefined;

0 commit comments

Comments
 (0)