diff --git a/package.xml b/package.xml index 7047d64..c15f6ae 100644 --- a/package.xml +++ b/package.xml @@ -88,6 +88,9 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + + diff --git a/php_v8js_macros.h b/php_v8js_macros.h index 3be9181..7d383da 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -184,6 +184,7 @@ struct php_v8js_ctx { std::vector modules_base; std::map template_cache; std::vector accessor_list; + char *tz; #ifdef ZTS void ***zts_ctx; #endif diff --git a/tests/timezones.phpt b/tests/timezones.phpt new file mode 100644 index 0000000..f2f8fc3 --- /dev/null +++ b/tests/timezones.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test V8::executeString() : Check timezone handling +--SKIPIF-- + +--FILE-- +executeString('print (new Date("Thu, 20 Mar 2014 09:03:24 +0000")).toString();'); + echo "\n"; +} catch (V8JsScriptException $e) { + var_dump($e->getMessage()); +} + +try { + putenv('TZ=America/New_York'); + $v8->executeString('print (new Date("Thu, 20 Mar 2014 09:03:24 +0000")).toString();'); + echo "\n"; +} catch (V8JsScriptException $e) { + var_dump($e->getMessage()); +} + +try { + putenv('TZ=Europe/Helsinki'); + $v8->executeString('print (new Date("Thu, 20 Mar 2014 09:03:24 +0000")).toString();'); + echo "\n"; +} catch (V8JsScriptException $e) { + var_dump($e->getMessage()); +} +?> +===EOF=== +--EXPECT-- +Thu Mar 20 2014 11:03:24 GMT+0200 (EET) +Thu Mar 20 2014 05:03:24 GMT-0400 (EDT) +Thu Mar 20 2014 11:03:24 GMT+0200 (EET) +===EOF=== diff --git a/v8js.cc b/v8js.cc index fc0ca80..a6ecb4c 100644 --- a/v8js.cc +++ b/v8js.cc @@ -1006,7 +1006,7 @@ static void php_v8js_timer_thread(TSRMLS_D) */ static PHP_METHOD(V8Js, executeString) { - char *str = NULL, *identifier = NULL; + char *str = NULL, *identifier = NULL, *tz = NULL; int str_len = 0, identifier_len = 0; long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0; @@ -1040,6 +1040,15 @@ static PHP_METHOD(V8Js, executeString) /* Set flags for runtime use */ V8JS_GLOBAL_SET_FLAGS(isolate, flags); + /* Check if timezone has been changed and notify V8 */ + tz = getenv("TZ"); + if (c->tz != NULL) { + if (c->tz != NULL && strcmp(c->tz, tz) != 0) { + v8::Date::DateTimeConfigurationChangeNotification(c->isolate); + } + } + c->tz = tz; + if (time_limit > 0 || memory_limit > 0) { // If timer thread is not running then start it if (!V8JSG(timer_thread)) {