Skip to content

Commit

Permalink
[intl] Implement ECMA402 PR758
Browse files Browse the repository at this point in the history
Spec tc39/ecma402#758

Change the hourCycle for not returning h24 while hour12 is false

Bug: v8:14542
Change-Id: I65a6719ed0da1fd43c3ac25bd107c89a25ae7f21
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5319663
Reviewed-by: Shu-yu Guo <[email protected]>
Commit-Queue: Frank Tang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#92519}
  • Loading branch information
FrankYFTang authored and V8 LUCI CQ committed Feb 24, 2024
1 parent a8ed338 commit f92857d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
68 changes: 42 additions & 26 deletions src/objects/js-date-time-format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ JSDateTimeFormat::HourCycle ToHourCycle(UDateFormatHourCycle hc) {
}
}

// The following two functions are hack until we add necessary API to ICU
// to get default hour cycle for 12 hours system (h11 or h12) or 24 hours system
// (h23 or h24).
// From timeData in third_party/icu/source/data/misc/supplementalData.txt
// we know the preferred values are either h or H.
// And all allowed values are also h or H except in JP K (h11) is listed before
// h (h12).
JSDateTimeFormat::HourCycle DefaultHourCycle12(
const icu::Locale& locale, JSDateTimeFormat::HourCycle defaultHourCycle) {
if (defaultHourCycle == JSDateTimeFormat::HourCycle::kH11 ||
defaultHourCycle == JSDateTimeFormat::HourCycle::kH12) {
return defaultHourCycle;
}
if (std::strcmp(locale.getCountry(), "JP") == 0) {
return JSDateTimeFormat::HourCycle::kH11;
}
return JSDateTimeFormat::HourCycle::kH12;
}

JSDateTimeFormat::HourCycle DefaultHourCycle24(
const icu::Locale& locale, JSDateTimeFormat::HourCycle defaultHourCycle) {
if (defaultHourCycle == JSDateTimeFormat::HourCycle::kH23 ||
defaultHourCycle == JSDateTimeFormat::HourCycle::kH24) {
return defaultHourCycle;
}
return JSDateTimeFormat::HourCycle::kH23;
}

Maybe<JSDateTimeFormat::HourCycle> GetHourCycle(Isolate* isolate,
Handle<JSReceiver> options,
const char* method_name) {
Expand Down Expand Up @@ -2297,36 +2325,24 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::CreateDateTimeFormat(
} else {
hc = hour_cycle;
}
// 17. If hc is null, then
if (hc == HourCycle::kUndefined) {
// a. Set hc to hcDefault.
hc = hc_default;
}

// 18. If hour12 is not undefined, then
// 25. If hour12 is true, then
if (maybe_get_hour12.FromJust()) {
// a. If hour12 is true, then
if (hour12) {
// i. If hcDefault is "h11" or "h23", then
if (hc_default == HourCycle::kH11 || hc_default == HourCycle::kH23) {
// 1. Set hc to "h11".
hc = HourCycle::kH11;
// ii. Else,
} else {
// 1. Set hc to "h12".
hc = HourCycle::kH12;
}
// b. Else,
// a. Let hc be dataLocaleData.[[hourCycle12]].
hc = DefaultHourCycle12(icu_locale, hc_default);
// 26. Else if hour12 is false, then
} else {
// ii. If hcDefault is "h11" or "h23", then
if (hc_default == HourCycle::kH11 || hc_default == HourCycle::kH23) {
// 1. Set hc to "h23".
hc = HourCycle::kH23;
// iii. Else,
} else {
// 1. Set hc to "h24".
hc = HourCycle::kH24;
}
// a. Let hc be dataLocaleData.[[hourCycle24]].
hc = DefaultHourCycle24(icu_locale, hc_default);
}
} else {
// 27. Else,
// a. Assert: hour12 is undefined.
// b. Let hc be r.[[hc]].
// c. If hc is null, set hc to dataLocaleData.[[hourCycle]].
if (hc == HourCycle::kUndefined) {
hc = hc_default;
}
}

Expand Down
1 change: 0 additions & 1 deletion test/test262/test262.status
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,6 @@
'built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/order-of-operations': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/getpossibleinstantsfor-called-with-iso8601-calendar': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/order-of-operations': [FAIL],
'intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default': [FAIL],
'intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined': [FAIL],
'intl402/DurationFormat/constructor-options-style-conflict': [FAIL],
'language/global-code/script-decl-lex-var-declared-via-eval-sloppy': [FAIL],
Expand Down

0 comments on commit f92857d

Please sign in to comment.