From 3064cc9a8723ab5616fa4f4fa52df631e1c77a6c Mon Sep 17 00:00:00 2001 From: "Gang Zhao (Hermes)" Date: Wed, 15 May 2024 13:03:14 -0700 Subject: [PATCH] Remove old daylightSavingTA() (#1245) Summary: Pull Request resolved: https://github.com/facebook/hermes/pull/1245 Reviewed By: avp Differential Revision: D52579225 --- include/hermes/VM/JSLib/DateUtil.h | 4 --- lib/VM/JSLib/DateUtil.cpp | 44 ---------------------------- unittests/VMRuntime/DateUtilTest.cpp | 5 ++++ 3 files changed, 5 insertions(+), 48 deletions(-) diff --git a/include/hermes/VM/JSLib/DateUtil.h b/include/hermes/VM/JSLib/DateUtil.h index a5f2125ba0a..0e2f884e4e3 100644 --- a/include/hermes/VM/JSLib/DateUtil.h +++ b/include/hermes/VM/JSLib/DateUtil.h @@ -112,10 +112,6 @@ double localTZA(); //===----------------------------------------------------------------------===// // ES5.1 15.9.1.8 -/// Daylight saving time adjustment, in milliseconds, at time \p t. -/// \param t timestamp in milliseconds. -double daylightSavingTA(double t); - namespace detail { // Exposed for test only int32_t equivalentTime(int64_t epochSecs); diff --git a/lib/VM/JSLib/DateUtil.cpp b/lib/VM/JSLib/DateUtil.cpp index bf5a9b3c40f..e8c42eebbe6 100644 --- a/lib/VM/JSLib/DateUtil.cpp +++ b/lib/VM/JSLib/DateUtil.cpp @@ -372,50 +372,6 @@ int32_t detail::equivalentTime(int64_t epochSecs) { return (eqYearAsEpochDays + dayOfYear) * SECONDS_PER_DAY + secsOfDay; } -double daylightSavingTA(double t) { - // The spec says LocalTime should only take finite time value and return 0 in - // case conversion fails. Once we enforce the finite input at the caller site, - // we should remove the below check or replace it with an assertion. For now, - // let's return NaN instead if it's not finite value. - if (!std::isfinite(t)) { - return std::numeric_limits::quiet_NaN(); - } - - // Convert t to seconds and get the actual time needed. - const double seconds = t / MS_PER_SECOND; - // If the number of seconds is higher or lower than a unix timestamp can - // support, clamp it. This is not correct in all cases, but returning NaN (for - // Invalid Date) breaks date construction entirely. Clamping only results in - // small errors in daylight savings time. This is only a problem in systems - // with a 32-bit time_t, like some Android systems. - time_t local = 0; - if (seconds > TIME_RANGE_SECS || seconds < -TIME_RANGE_SECS) { - // Return NaN if input is outside Time Range allowed in ES5.1 - return std::numeric_limits::quiet_NaN(); - } - // This will truncate any fractional seconds, which is ok for daylight - // savings time calculations. - local = detail::equivalentTime(static_cast(seconds)); - - std::tm tm; -#ifdef _WINDOWS - // The return value of localtime_s on Windows is an error code instead of - // a pointer to std::tm. For simplicity, we don't inspect the concrete error - // code and just return 0. - auto err = ::localtime_s(&tm, &local); - if (err) { - return 0; - } -#else - std::tm *brokenTime = ::localtime_r(&local, &tm); - if (!brokenTime) { - // Local time is invalid. - return 0; - } -#endif - return tm.tm_isdst ? MS_PER_HOUR : 0; -} - //===----------------------------------------------------------------------===// // ES5.1 15.9.1.9 diff --git a/unittests/VMRuntime/DateUtilTest.cpp b/unittests/VMRuntime/DateUtilTest.cpp index e97eafb19f4..e282a779935 100644 --- a/unittests/VMRuntime/DateUtilTest.cpp +++ b/unittests/VMRuntime/DateUtilTest.cpp @@ -130,6 +130,11 @@ void setTimeZone(const char *tzname) { hermes::oscompat::set_env("TZ", tzname); ::tzset(); } + +/// A wrapper that implements the deleted daylightSavingTA() function. +double daylightSavingTA(double timeMs) { + return getLocalTimeOffsetCache().daylightSavingOffsetInMs(timeMs); +} } // namespace TEST(DateUtilTest, LocalTZATest) {