Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-05-11 19:10:46 +0300
committerJames M Snell <jasnell@gmail.com>2021-05-17 22:02:49 +0300
commit16cb4f720b43345c9ed34f4a67165e86fbba5b90 (patch)
tree04fdde70aa88178e21ecc71b4d60b0ed932c0255 /src/node_env_var.cc
parent75340f3c524cbe8602ba8f5a48b8bf8572bad8f1 (diff)
lib: support setting process.env.TZ on windows
Fixes: https://github.com/nodejs/node/issues/4230 Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/38642 Reviewed-By: Steven R Loomis <srloomis@us.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/node_env_var.cc')
-rw-r--r--src/node_env_var.cc26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/node_env_var.cc b/src/node_env_var.cc
index e6d9573ca7c..b13f7fcd16f 100644
--- a/src/node_env_var.cc
+++ b/src/node_env_var.cc
@@ -2,6 +2,7 @@
#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
+#include "node_i18n.h"
#include "node_process.h"
#include <time.h> // tzset(), _tzset()
@@ -69,15 +70,32 @@ std::shared_ptr<KVStore> system_environment = std::make_shared<RealEnvStore>();
} // namespace per_process
template <typename T>
-void DateTimeConfigurationChangeNotification(Isolate* isolate, const T& key) {
+void DateTimeConfigurationChangeNotification(
+ Isolate* isolate,
+ const T& key,
+ const char* val = nullptr) {
if (key.length() == 2 && key[0] == 'T' && key[1] == 'Z') {
#ifdef __POSIX__
tzset();
+ isolate->DateTimeConfigurationChangeNotification(
+ Isolate::TimeZoneDetection::kRedetect);
#else
_tzset();
+
+# if defined(NODE_HAVE_I18N_SUPPORT)
+ isolate->DateTimeConfigurationChangeNotification(
+ Isolate::TimeZoneDetection::kSkip);
+
+ // On windows, the TZ environment is not supported out of the box.
+ // By default, v8 will only be able to detect the system configured
+ // timezone. This supports using the TZ environment variable to set
+ // the default timezone instead.
+ if (val != nullptr) i18n::SetDefaultTimeZone(val);
+# else
+ isolate->DateTimeConfigurationChangeNotification(
+ Isolate::TimeZoneDetection::kRedetect);
+# endif
#endif
- auto constexpr time_zone_detection = Isolate::TimeZoneDetection::kRedetect;
- isolate->DateTimeConfigurationChangeNotification(time_zone_detection);
}
}
@@ -128,7 +146,7 @@ void RealEnvStore::Set(Isolate* isolate,
if (key.length() > 0 && key[0] == '=') return;
#endif
uv_os_setenv(*key, *val);
- DateTimeConfigurationChangeNotification(isolate, key);
+ DateTimeConfigurationChangeNotification(isolate, key, *val);
}
int32_t RealEnvStore::Query(const char* key) const {