|
4 | 4 | #include "node_external_reference.h"
|
5 | 5 | #include "node_process.h"
|
6 | 6 |
|
| 7 | +#include "unicode/timezone.h" |
| 8 | + |
7 | 9 | #include <time.h> // tzset(), _tzset()
|
8 | 10 |
|
9 | 11 | namespace node {
|
@@ -69,16 +71,30 @@ std::shared_ptr<KVStore> system_environment = std::make_shared<RealEnvStore>();
|
69 | 71 | } // namespace per_process
|
70 | 72 |
|
71 | 73 | template <typename T>
|
72 |
| -void DateTimeConfigurationChangeNotification(Isolate* isolate, const T& key) { |
| 74 | +void DateTimeConfigurationChangeNotification(Isolate* isolate, const T& key, const char* val = nullptr) { |
73 | 75 | if (key.length() == 2 && key[0] == 'T' && key[1] == 'Z') {
|
| 76 | + auto constexpr time_zone_detection = Isolate::TimeZoneDetection::kRedetect; |
74 | 77 | #ifdef __POSIX__
|
75 | 78 | tzset();
|
76 | 79 | #else
|
77 | 80 | _tzset();
|
78 | 81 | #endif
|
79 |
| - auto constexpr time_zone_detection = Isolate::TimeZoneDetection::kRedetect; |
80 | 82 | isolate->DateTimeConfigurationChangeNotification(time_zone_detection);
|
| 83 | + |
| 84 | +// On windows, the TZ environment is not supported out of the box. |
| 85 | +// By default, v8 will only be able to detect the system configured |
| 86 | +// timezone. This supports using the TZ environment variable to set |
| 87 | +// the default timezone instead. |
| 88 | +#ifndef __POSIX__ |
| 89 | + if (val != nullptr) { |
| 90 | + icu::UnicodeString id = |
| 91 | + icu::UnicodeString::fromUTF8(icu::StringPiece(val)); |
| 92 | + icu::TimeZone* tz = icu::TimeZone::createTimeZone(id); |
| 93 | + if (*tz != icu::TimeZone::getUnknown()) |
| 94 | + icu::TimeZone::adoptDefault(tz); |
| 95 | + } |
81 | 96 | }
|
| 97 | +#endif |
82 | 98 | }
|
83 | 99 |
|
84 | 100 | Maybe<std::string> RealEnvStore::Get(const char* key) const {
|
@@ -128,7 +144,7 @@ void RealEnvStore::Set(Isolate* isolate,
|
128 | 144 | if (key.length() > 0 && key[0] == '=') return;
|
129 | 145 | #endif
|
130 | 146 | uv_os_setenv(*key, *val);
|
131 |
| - DateTimeConfigurationChangeNotification(isolate, key); |
| 147 | + DateTimeConfigurationChangeNotification(isolate, key, *val); |
132 | 148 | }
|
133 | 149 |
|
134 | 150 | int32_t RealEnvStore::Query(const char* key) const {
|
|
0 commit comments