按照ecma标准修改方舟JSDateTimeFormat::InitializeDateTimeFormat

Signed-off-by: yanpeng <yanpeng51@huawei.com>
Change-Id: Iba732e8d876bcd0ce629cbc12a8b20f4700476aa
This commit is contained in:
yanpeng 2023-12-22 10:57:35 +08:00
parent 8602729bf8
commit 1c034a62bc
5 changed files with 82 additions and 0 deletions

View File

@ -511,10 +511,17 @@ JSHandle<JSDateTimeFormat> JSDateTimeFormat::InitializeDateTimeFormat(JSThread *
for (const IcuPatternDesc &item : data) {
// prop be [[TimeZoneName]]
if (item.property == "timeZoneName") {
// b. If prop is "fractionalSecondDigits", then
// i. Let value be ? GetNumberOption(options, "fractionalSecondDigits", 1, 3, undefined).
int secondDigitsString = JSLocale::GetNumberOption(thread, dateTimeOptions,
globalConst->GetHandledFractionalSecondDigitsString(),
1, 3, 0);
skeleton.append(secondDigitsString, 'S');
// e. If value is not undefined, then
// i. Set hasExplicitFormatComponents to true.
if (secondDigitsString > 0) {
explicitFormatComponents = 1;
}
}
JSHandle<JSTaggedValue> property(thread, factory->NewFromStdString(item.property).GetTaggedValue());
std::string value;

View File

@ -119,6 +119,8 @@ group("ark_js_moduletest") {
"regexpcallthrow",
"regexpflagd",
"regress",
#"regressdatetime",
"regressdefineproperty",
"require",
"setobjectwithproto",

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("regressdatetime") {
deps = []
}

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
1
2
3
undefined
undefined

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
() => (new Intl.DateTimeFormat("en", {fractionalSecondDigits: 0}));
() => (new Intl.DateTimeFormat("en", {fractionalSecondDigits: 4}));
print((new Intl.DateTimeFormat("en", {fractionalSecondDigits: 1}))
.resolvedOptions().fractionalSecondDigits);
print((new Intl.DateTimeFormat("en", {fractionalSecondDigits: 2}))
.resolvedOptions().fractionalSecondDigits);
print((new Intl.DateTimeFormat("en", {fractionalSecondDigits: 3}))
.resolvedOptions().fractionalSecondDigits);
print((new Intl.DateTimeFormat()).resolvedOptions().fractionalSecondDigits);
print((new Intl.DateTimeFormat("en", {fractionalSecondDigits: undefined}))
.resolvedOptions().fractionalSecondDigits);
() => (new Intl.DateTimeFormat(
"en", {timeStyle: "short", fractionalSecondDigits: 3}));
() => (new Intl.DateTimeFormat(
"en", {dateStyle: "short", fractionalSecondDigits: 3}));