diff --git a/BUILD.gn b/BUILD.gn index eeb318d6af4cf513f2d79da39e891e8f7857e6ae..cd5d07260056cf39cd5a1845f29261b5d355b59d 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 0000000000000000000000000000000000000000..93ac1826a66643ecbcd22724d2b7953594c4a96d --- /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 fd393531dc201c74bead92b2354570b803685d18..ff1e00407644eb28cec63b2b4b4cfea99f3a89cd 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 2049fae296c5eda65d0b9377e33c88154d798202..c4c37294f4b79aa1dac6f24e333972b8a3b49429 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