Skip to content

Commit

Permalink
Merge pull request #6 from kiddivouchers/issue/52-fix-non-tz-tzs
Browse files Browse the repository at this point in the history
Fix error with non standard timezone
  • Loading branch information
cs278 authored Jul 19, 2021
2 parents 53e7722 + 70ad5fd commit 7de584b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
20 changes: 20 additions & 0 deletions tests/issue_052.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Check timezone '+00:00' being allowed
--SKIPIF--
<?php
$required_func = array("timecop_freeze");
include(__DIR__."/tests-skipcheck.inc.php");
--INI--
date.timezone=America/Los_Angeles
timecop.func_override=1
--FILE--
<?php
$dt1 = new \DateTime('@0', new \DateTimeZone('+00:00'));
var_dump($dt1->format("Y-m-d H:i:s.uP"));

timecop_freeze(0);
$dt2 = new \DateTime('@0', new \DateTimeZone('+00:00'));
var_dump($dt2->format("Y-m-d H:i:s.uP"));
--EXPECT--
string(32) "1970-01-01 00:00:00.000000+00:00"
string(32) "1970-01-01 00:00:00.000000+00:00"
17 changes: 1 addition & 16 deletions timecop_php5.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,27 +846,12 @@ static int get_formatted_mock_time(zval *time, zval *timezone_obj, zval **retval

get_mock_timeval(&now, NULL TSRMLS_CC);

if (timezone_obj && Z_TYPE_P(timezone_obj) == IS_OBJECT) {
zval *zonename;
call_php_method_with_0_params(&timezone_obj, Z_OBJCE_PP(&timezone_obj), "getname", &zonename);
if (zonename) {
call_php_function_with_0_params("date_default_timezone_get", &orig_zonename);
if (orig_zonename) {
call_php_function_with_1_params("date_default_timezone_set", NULL, zonename);
}
zval_ptr_dtor(&zonename);
}
}
// @todo Restore removed timezone handling code? https://github.com/kiddivouchers/php-timecop/pull/6

INIT_ZVAL(now_timestamp);
ZVAL_LONG(&now_timestamp, now.sec);
call_php_function_with_2_params(ORIG_FUNC_NAME("strtotime"), &fixed_sec, time, &now_timestamp);

if (timezone_obj && Z_TYPE_P(timezone_obj) == IS_OBJECT) {
call_php_function_with_1_params("date_default_timezone_set", NULL, orig_zonename);
zval_ptr_dtor(&orig_zonename);
}

if (Z_TYPE_P(fixed_sec) == IS_BOOL && !Z_BVAL_P(fixed_sec)) {
/* $fixed_sec === false */
MAKE_STD_ZVAL(*retval_time);
Expand Down
13 changes: 1 addition & 12 deletions timecop_php7.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,22 +803,11 @@ static int get_formatted_mock_time(zval *time, zval *timezone_obj, zval *retval_

get_mock_timeval(&now, NULL);

if (timezone_obj && Z_TYPE_P(timezone_obj) == IS_OBJECT) {
zval zonename;
call_php_method_with_0_params(timezone_obj, Z_OBJCE_P(timezone_obj), "getname", &zonename);
call_php_function_with_0_params("date_default_timezone_get", &orig_zonename);
call_php_function_with_1_params("date_default_timezone_set", NULL, &zonename);
zval_ptr_dtor(&zonename);
}
// @todo Restore removed timezone handling code? https://github.com/kiddivouchers/php-timecop/pull/6

ZVAL_LONG(&now_timestamp, now.sec);
call_php_function_with_2_params(ORIG_FUNC_NAME("strtotime"), &fixed_sec, time, &now_timestamp);

if (timezone_obj && Z_TYPE_P(timezone_obj) == IS_OBJECT) {
call_php_function_with_1_params("date_default_timezone_set", NULL, &orig_zonename);
zval_ptr_dtor(&orig_zonename);
}

if (Z_TYPE(fixed_sec) == IS_FALSE) {
ZVAL_FALSE(retval_time);
ZVAL_NULL(retval_timezone);
Expand Down

0 comments on commit 7de584b

Please sign in to comment.