Skip to content

Commit 5c7dbc0

Browse files
troZeecipolleschi
authored andcommitted
add IHermes::resetTimezoneCache()
Summary: `IHermes::resetTimezoneCache()` must be called by the integrator when a timezone change has been detected. Reviewed By: dannysu Differential Revision: D75544519 Pulled By: tmikov fbshipit-source-id: 3b698d2768eb7e226963f95018cd1d0758d9012d
1 parent 4eb6132 commit 5c7dbc0

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

API/hermes/hermes.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "hermes/VM/JSArray.h"
2929
#include "hermes/VM/JSArrayBuffer.h"
3030
#include "hermes/VM/JSLib.h"
31+
#include "hermes/VM/JSLib/JSLibStorage.h"
3132
#include "hermes/VM/JSLib/RuntimeJSONUtils.h"
3233
#include "hermes/VM/NativeState.h"
3334
#include "hermes/VM/Operations.h"
@@ -1070,6 +1071,7 @@ class HermesRuntimeImpl final : public HermesRuntime,
10701071

10711072
/// Concrete declarations of HermesRuntime methods.
10721073
void sampledTraceToStreamInDevToolsFormat(std::ostream &stream) override;
1074+
void resetTimezoneCache() override;
10731075
sampling_profiler::Profile dumpSampledTraceToProfile() override;
10741076
void loadSegment(
10751077
std::unique_ptr<const jsi::Buffer> buffer,
@@ -1285,6 +1287,10 @@ class BufferAdapter final : public ::hermes::Buffer {
12851287
};
12861288
} // namespace
12871289

1290+
void HermesRuntimeImpl::resetTimezoneCache() {
1291+
runtime_.getJSLibStorage()->localTimeOffsetCache.reset();
1292+
}
1293+
12881294
void HermesRuntimeImpl::loadSegment(
12891295
std::unique_ptr<const jsi::Buffer> buffer,
12901296
const jsi::Value &context) {

API/hermes/hermes.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,16 @@ class HERMES_EXPORT HermesRuntime : public jsi::Runtime {
122122
/// be used by third parties.
123123
virtual sampling_profiler::Profile dumpSampledTraceToProfile() = 0;
124124

125-
// The base class declares most of the interesting methods. This
126-
// just declares new methods which are specific to HermesRuntime.
127-
// The actual implementations of the pure virtual methods are
128-
// provided by a class internal to the .cpp file, which is created
129-
// by the factory.
125+
/// Resets the timezone offset cache used by Hermes for performance
126+
/// optimization. Hermes maintains a cached timezone offset to accelerate date
127+
/// and time calculations. However, this cache does not automatically detect
128+
/// changes to the system timezone. When the system timezone changes, the
129+
/// integration layer (e.g., React Native) must call this method to invalidate
130+
/// the cache and ensure correct time calculations.
131+
///
132+
/// \note Call this method immediately after detecting any timezone change in
133+
/// the integrator.
134+
virtual void resetTimezoneCache() = 0;
130135

131136
/// Load a new segment into the Runtime.
132137
/// The \param context must be a valid RequireContext retrieved from JS

unittests/API/APITest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ TEST_P(HermesRuntimeTest, StrictHostFunctionBindTest) {
9898
.getBool());
9999
}
100100

101+
TEST_P(HermesRuntimeTest, ResetTimezoneCache) {
102+
if (auto *hrt = castInterface<IHermes>(rt.get())) {
103+
EXPECT_NO_THROW({ hrt->resetTimezoneCache(); });
104+
}
105+
}
106+
101107
TEST_P(HermesRuntimeTest, DescriptionTest) {
102108
// Minimally, if the description doesn't include "Hermes", something
103109
// is wrong.

0 commit comments

Comments
 (0)