BugFix:Fix UT errors in DateTimeFormat_004

Setting timezone in DateTimeFormat_004
issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I8DP9I

Signed-off-by: hecunmao <hecunmao@huawei.com>
Change-Id: I05a9f0f5d694b8eea4c2cc995815abdc904972b5
This commit is contained in:
hecunmao 2023-11-03 20:38:54 +08:00
parent 3fa37c9f1e
commit 384230a49c
3 changed files with 12 additions and 9 deletions

View File

@ -662,13 +662,16 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, DateTimeFormat_004)
JSHandle<JSTaggedValue> dateStyleValue(factory->NewFromASCII("dateStyle")); JSHandle<JSTaggedValue> dateStyleValue(factory->NewFromASCII("dateStyle"));
JSHandle<JSTaggedValue> timeStyleeValue(factory->NewFromASCII("timeStyle")); JSHandle<JSTaggedValue> timeStyleeValue(factory->NewFromASCII("timeStyle"));
JSHandle<JSTaggedValue> hour12Value(factory->NewFromASCII("hour12")); JSHandle<JSTaggedValue> hour12Value(factory->NewFromASCII("hour12"));
JSHandle<JSTaggedValue> timeZone(factory->NewFromASCII("timeZone"));
JSHandle<JSTaggedValue> timeZoneValue(factory->NewFromASCII("UTC"));
JSObject::SetProperty(thread, optionsObj, dateStyleValue, fullValue); JSObject::SetProperty(thread, optionsObj, dateStyleValue, fullValue);
JSObject::SetProperty(thread, optionsObj, timeStyleeValue, fullValue); JSObject::SetProperty(thread, optionsObj, timeStyleeValue, fullValue);
JSObject::SetProperty(thread, optionsObj, hour12Value, falseValue); JSObject::SetProperty(thread, optionsObj, hour12Value, falseValue);
JSObject::SetProperty(thread, optionsObj, timeZone, timeZoneValue);
auto constructorResult = JSDateTimeFormatConstructor(thread, optionsObj, localesString); auto constructorResult = JSDateTimeFormatConstructor(thread, optionsObj, localesString);
JSHandle<EcmaString> resultStr = JSHandle<EcmaString> resultStr =
JSDateTimeFormat::FormatDateTime(thread, JSHandle<JSDateTimeFormat>(thread, constructorResult), 0.0); JSDateTimeFormat::FormatDateTime(thread, JSHandle<JSDateTimeFormat>(thread, constructorResult), 0.0);
EXPECT_STREQ("1970年1月1日星期四 中国标准时间 08:00:00", EcmaStringAccessor(resultStr).ToCString().c_str()); EXPECT_STREQ("1970年1月1日星期四 协调世界时 00:00:00", EcmaStringAccessor(resultStr).ToCString().c_str());
} }
} // namespace panda::test } // namespace panda::test

View File

@ -293,9 +293,9 @@ icu::UnicodeString ReplaceSkeleton(const icu::UnicodeString input, HourCycleOpti
} }
std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(DateTimeStyleOption dateStyle, std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(DateTimeStyleOption dateStyle,
DateTimeStyleOption timeStyle, DateTimeStyleOption timeStyle,
icu::Locale &icuLocale, icu::Locale &icuLocale,
HourCycleOption hc, HourCycleOption hc,
icu::DateTimePatternGenerator *generator) icu::DateTimePatternGenerator *generator)
{ {
std::unique_ptr<icu::SimpleDateFormat> result; std::unique_ptr<icu::SimpleDateFormat> result;
@ -304,7 +304,7 @@ std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(DateTimeStyleOption
result.reset(reinterpret_cast<icu::SimpleDateFormat *>( result.reset(reinterpret_cast<icu::SimpleDateFormat *>(
icu::DateFormat::createDateTimeInstance(icuDateStyle, icuTimeStyle, icuLocale))); icu::DateFormat::createDateTimeInstance(icuDateStyle, icuTimeStyle, icuLocale)));
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString pattern; icu::UnicodeString pattern("");
pattern = result->toPattern(pattern); pattern = result->toPattern(pattern);
icu::UnicodeString skeleton = icu::DateTimePatternGenerator::staticGetSkeleton(pattern, status); icu::UnicodeString skeleton = icu::DateTimePatternGenerator::staticGetSkeleton(pattern, status);
ASSERT_PRINT(U_SUCCESS(status), "staticGetSkeleton failed"); ASSERT_PRINT(U_SUCCESS(status), "staticGetSkeleton failed");
@ -583,7 +583,7 @@ JSHandle<JSDateTimeFormat> JSDateTimeFormat::InitializeDateTimeFormat(JSThread *
if (explicitFormatComponents != 0) { if (explicitFormatComponents != 0) {
THROW_TYPE_ERROR_AND_RETURN(thread, "Invalid option : option", dateTimeFormat); THROW_TYPE_ERROR_AND_RETURN(thread, "Invalid option : option", dateTimeFormat);
} }
simpleDateFormatIcu = DateTimeStylePattern(dateStyle, timeStyle, icuLocale, simpleDateFormatIcu = DateTimeStylePattern(dateStyle, timeStyle, icuLocale,
hc, generator.get()); hc, generator.get());
} }
if (U_FAILURE(status) != 0) { if (U_FAILURE(status) != 0) {

View File

@ -46,9 +46,9 @@ icu::DateFormat::EStyle DateTimeStyleToEStyle(DateTimeStyleOption style);
HourCycleOption HourCycleFromPattern(const icu::UnicodeString pattern); HourCycleOption HourCycleFromPattern(const icu::UnicodeString pattern);
icu::UnicodeString ReplaceSkeleton(const icu::UnicodeString input, HourCycleOption hc); icu::UnicodeString ReplaceSkeleton(const icu::UnicodeString input, HourCycleOption hc);
std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(DateTimeStyleOption dateStyle, std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(DateTimeStyleOption dateStyle,
DateTimeStyleOption timeStyle, DateTimeStyleOption timeStyle,
icu::Locale &icuLocale, icu::Locale &icuLocale,
HourCycleOption hc, HourCycleOption hc,
icu::DateTimePatternGenerator *generator); icu::DateTimePatternGenerator *generator);
using IcuPatternDescVect = std::vector<IcuPatternDesc>; using IcuPatternDescVect = std::vector<IcuPatternDesc>;