diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2019-05-23 12:34:15 +0300 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2019-05-23 12:34:17 +0300 |
commit | eba348b6aecf5c764f786f6f049431237702c88f (patch) | |
tree | 45d2ffc647f3b85d8ef05ed1e2a8878d6348f4be /src/node_env_var.cc | |
parent | 58fe440c0f62865caf1fbb5b668f0413afbd1c9c (diff) |
src: make process.env.TZ setter clear tz cache
Since the presence of the libc and V8 timezone caches seem to be
a perennial source of confusion to users ("why doesn't it work?!"),
let's try to support that pattern by intercepting assignments to
the TZ environment variable and reset the caches as a side effect.
Fixes: https://github.com/nodejs/node/issues/19974
PR-URL: https://github.com/nodejs/node/pull/20026
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Steven R Loomis <srloomis@us.ibm.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/node_env_var.cc')
-rw-r--r-- | src/node_env_var.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/node_env_var.cc b/src/node_env_var.cc index 717c675d9a7..ef2b78d6648 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -2,6 +2,8 @@ #include "node_errors.h" #include "node_process.h" +#include <time.h> // tzset(), _tzset() + #ifdef __APPLE__ #include <crt_externs.h> #define environ (*_NSGetEnviron()) @@ -64,6 +66,19 @@ Mutex env_var_mutex; std::shared_ptr<KVStore> system_environment = std::make_shared<RealEnvStore>(); } // namespace per_process +template <typename T> +void DateTimeConfigurationChangeNotification(Isolate* isolate, const T& key) { + if (key.length() == 2 && key[0] == 'T' && key[1] == 'Z') { +#ifdef __POSIX__ + tzset(); +#else + _tzset(); +#endif + auto constexpr time_zone_detection = Isolate::TimeZoneDetection::kRedetect; + isolate->DateTimeConfigurationChangeNotification(time_zone_detection); + } +} + Local<String> RealEnvStore::Get(Isolate* isolate, Local<String> property) const { Mutex::ScopedLock lock(per_process::env_var_mutex); @@ -115,6 +130,7 @@ void RealEnvStore::Set(Isolate* isolate, SetEnvironmentVariableW(key_ptr, reinterpret_cast<WCHAR*>(*val)); } #endif + DateTimeConfigurationChangeNotification(isolate, key); } int32_t RealEnvStore::Query(Isolate* isolate, Local<String> property) const { @@ -150,6 +166,7 @@ void RealEnvStore::Delete(Isolate* isolate, Local<String> property) { WCHAR* key_ptr = reinterpret_cast<WCHAR*>(*key); SetEnvironmentVariableW(key_ptr, nullptr); #endif + DateTimeConfigurationChangeNotification(isolate, key); } Local<Array> RealEnvStore::Enumerate(Isolate* isolate) const { |