From 7e55637ac9a1f55cb263265266ebf59e3f9d4321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E6=9D=B0?= Date: Fri, 29 Aug 2025 09:53:33 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E9=9C=80=E6=B1=82]:=20=E6=8C=91?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICVCF3 Signed-off-by: 唐杰 --- BUILD.gn | 5 ++- ecmascript/platform/unix/ohos/time.cpp | 51 ++++++++++++++++++++++ test/moduletest/datecase/datecase.js | 8 +++- test/moduletest/datecase/expect_output.txt | 5 +++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 ecmascript/platform/unix/ohos/time.cpp diff --git a/BUILD.gn b/BUILD.gn index eeb318d6af..cd5d072600 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1319,7 +1319,6 @@ if (is_mingw) { "common_components/platform/unix/map.cpp", "ecmascript/platform/unix/file.cpp", "ecmascript/platform/unix/map.cpp", - "ecmascript/platform/unix/time.cpp", "ecmascript/platform/unix/aot_crash_info.cpp", ] if (is_mac) { @@ -1331,6 +1330,7 @@ if (is_mingw) { "ecmascript/platform/unix/mac/backtrace.cpp", "ecmascript/platform/unix/mac/async_detect.cpp", "ecmascript/platform/unix/mac/log.cpp", + "ecmascript/platform/unix/time.cpp", "ecmascript/platform/unix/mac/dfx_hisys_event.cpp", "ecmascript/platform/unix/mac/pandafile.cpp", "ecmascript/platform/unix/mac/module.cpp", @@ -1347,6 +1347,7 @@ if (is_mingw) { "ecmascript/platform/unix/mac/async_detect.cpp", "ecmascript/platform/common/dfx_crash_obj.cpp", "ecmascript/platform/common/log.cpp", + "ecmascript/platform/unix/time.cpp", "ecmascript/platform/unix/mac/dfx_hisys_event.cpp", "ecmascript/platform/common/pandafile.cpp", "ecmascript/platform/common/module.cpp", @@ -1362,6 +1363,7 @@ if (is_mingw) { "ecmascript/platform/unix/ohos/backtrace.cpp", "ecmascript/platform/unix/ohos/async_detect.cpp", "ecmascript/platform/common/log.cpp", + "ecmascript/platform/unix/ohos/time.cpp", "ecmascript/platform/unix/ohos/memory.cpp", "ecmascript/platform/unix/ohos/dfx_hisys_event.cpp", "ecmascript/platform/common/module.cpp", @@ -1398,6 +1400,7 @@ if (is_mingw) { "ecmascript/platform/unix/linux/async_detect.cpp", "ecmascript/platform/common/dfx_crash_obj.cpp", "ecmascript/platform/common/log.cpp", + "ecmascript/platform/unix/time.cpp", "ecmascript/platform/unix/linux/memory.cpp", "ecmascript/platform/unix/linux/dfx_hisys_event.cpp", "ecmascript/platform/unix/linux/pandafile.cpp", diff --git a/ecmascript/platform/unix/ohos/time.cpp b/ecmascript/platform/unix/ohos/time.cpp new file mode 100644 index 0000000000..93ac1826a6 --- /dev/null +++ b/ecmascript/platform/unix/ohos/time.cpp @@ -0,0 +1,51 @@ +/* ++ * Copyright (c) 2024 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. ++ */ + +#include "ecmascript/platform/time.h" + +#include + +namespace panda::ecmascript { +static constexpr uint16_t THOUSAND = 1000; +static constexpr int SEC_PER_MINUTE = 60; + +int64_t GetLocalOffsetFromOS(int64_t timeMs, bool isLocal) +{ + if (!isLocal) { + return 0; + } + timeMs /= THOUSAND; + time_t tv = timeMs; + struct tm tm { + }; + struct tm *t = localtime_noenv_r(&tv, &tm); + if (t == nullptr) { + return 0; + } + + return t->tm_gmtoff / SEC_PER_MINUTE; +} + +bool IsDst(int64_t timeMs) +{ + timeMs /= THOUSAND; + time_t tv = timeMs; + struct tm tm { + }; + struct tm *t = nullptr; + t = localtime_noenv_r(&tv, &tm); + return (t != nullptr) && t->tm_isdst; +} +} // namespace panda::ecmascript \ No newline at end of file diff --git a/test/moduletest/datecase/datecase.js b/test/moduletest/datecase/datecase.js index fd393531dc..ff1e004076 100644 --- a/test/moduletest/datecase/datecase.js +++ b/test/moduletest/datecase/datecase.js @@ -56,4 +56,10 @@ print(d9.getMonth() == 1); print(d9.getDate() == 1); print(d9.getHours() == 0); -print(d10.getMonth(),d10.getDate(),d10.getHours()); \ No newline at end of file +print(d10.getMonth(),d10.getDate(),d10.getHours()); + +print(Date.parse("1972T23:50:03.500+01:00")); +print(Date.parse("1972T23:50:03.500Z")); +print(Date.parse("1972T23:50:03.500Z")); +print(Date.parse("1972T23:50:03Z")); +print(Date.parse("1972Z")); \ No newline at end of file diff --git a/test/moduletest/datecase/expect_output.txt b/test/moduletest/datecase/expect_output.txt index 2049fae296..c4c37294f4 100644 --- a/test/moduletest/datecase/expect_output.txt +++ b/test/moduletest/datecase/expect_output.txt @@ -32,3 +32,8 @@ true true true 2 26 23 +63154203500 +63157803500 +63157803500 +63157803000 +63072000000 -- Gitee