Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JSC] Implement Intl.DateTimeFormat dayPeriod
https://bugs.webkit.org/show_bug.cgi?id=215839 Reviewed by Ross Kirsling. JSTests: * stress/intl-datetimeformat-day-period.js: Added. (shouldBe): (throw.new.Error): * test262/config.yaml: Source/JavaScriptCore: This patch implements Intl.DateTimeFormat dayPeriod option[1]. We can use "narrow", "short", or "long" for dayPeriod, and it determines how "AM" etc. is represented. [1]: tc39/ecma402#346 * builtins/DatePrototype.js: (toLocaleString.toDateTimeOptionsAnyAll): (toLocaleString): (toLocaleTimeString.toDateTimeOptionsTimeTime): (toLocaleTimeString): * bytecode/BytecodeIntrinsicRegistry.cpp: (JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry): * bytecode/BytecodeIntrinsicRegistry.h: * runtime/CommonIdentifiers.h: * runtime/IntlDateTimeFormat.cpp: (JSC::toDateTimeOptionsAnyDate): (JSC::IntlDateTimeFormat::setFormatsFromPattern): (JSC::IntlDateTimeFormat::initializeDateTimeFormat): (JSC::IntlDateTimeFormat::dayPeriodString): (JSC::IntlDateTimeFormat::resolvedOptions const): * runtime/IntlDateTimeFormat.h: * runtime/OptionsList.h: Canonical link: https://commits.webkit.org/228759@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266323 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
83876d4
commit 4fbb0d8
Showing
11 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//@ runDefault("--useIntlDateTimeFormatDayPeriod=1") | ||
|
||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error(`expected ${expected} but got ${actual}`); | ||
} | ||
|
||
{ | ||
let dtf = new Intl.DateTimeFormat("en", {hour: "numeric", dayPeriod: "short"}); | ||
shouldBe(dtf.format(new Date("2019-05-20T07:00:00")), "7 in the morning"); | ||
|
||
{ | ||
let expected = [ | ||
{type: "hour", value: "7"}, | ||
{type: "literal", value: " "}, | ||
{type: "dayPeriod", value: "in the morning"} | ||
]; | ||
let actual = dtf.formatToParts(new Date("2019-05-20T07:00:00")); | ||
shouldBe(actual.length, expected.length); | ||
for (let index = 0; index < expected.length; ++index) { | ||
shouldBe(actual[index].type, expected[index].type); | ||
shouldBe(actual[index].value, expected[index].value); | ||
} | ||
} | ||
|
||
shouldBe(dtf.format(new Date("2019-05-20T11:59:00")), "11 in the morning"); | ||
shouldBe(dtf.format(new Date("2019-05-20T12:00:00")), "12 noon"); | ||
shouldBe(dtf.format(new Date("2019-05-20T13:00:00")), "1 in the afternoon"); | ||
shouldBe(dtf.format(new Date("2019-05-20T18:00:00")), "6 in the evening"); | ||
shouldBe(dtf.format(new Date("2019-05-20T22:00:00")), "10 at night"); | ||
|
||
dtf = new Intl.DateTimeFormat("zh-Hant", {hour: "numeric", dayPeriod: "short"}); | ||
shouldBe(dtf.format(new Date("2019-05-20T07:00:00")), "清晨7時"); | ||
{ | ||
let expected = [ | ||
{type: "dayPeriod", value: "清晨"}, | ||
{type: "hour", value: "7"}, | ||
{type: "literal", value: "時"} | ||
]; | ||
let actual = dtf.formatToParts(new Date("2019-05-20T07:00:00")); | ||
shouldBe(actual.length, expected.length); | ||
for (let index = 0; index < expected.length; ++index) { | ||
shouldBe(actual[index].type, expected[index].type); | ||
shouldBe(actual[index].value, expected[index].value); | ||
} | ||
} | ||
shouldBe(dtf.format(new Date("2019-05-20T11:59:00")), "上午11時"); | ||
shouldBe(dtf.format(new Date("2019-05-20T12:00:00")), "中午12時"); | ||
shouldBe(dtf.format(new Date("2019-05-20T13:00:00")), "下午1時"); | ||
shouldBe(dtf.format(new Date("2019-05-20T18:00:00")), "下午6時"); | ||
shouldBe(dtf.format(new Date("2019-05-20T22:00:00")), "晚上10時"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters