From a5a7c8228feec465b9aaad6c89c6b62d98aaa9f5 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 21 Jun 2021 16:19:21 +0100 Subject: [PATCH 1/4] Add failing test --- tests/issue_052.phpt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/issue_052.phpt diff --git a/tests/issue_052.phpt b/tests/issue_052.phpt new file mode 100644 index 0000000..7b24331 --- /dev/null +++ b/tests/issue_052.phpt @@ -0,0 +1,20 @@ +--TEST-- +Check timezone '+00:00' being allowed +--SKIPIF-- +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" From 058d97d3af7e1e4acb4287f279ce1c3ce74e867f Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 21 Jun 2021 16:19:50 +0100 Subject: [PATCH 2/4] Remove redundant code All tests pass with this code removed, presumably there is an edge case that actually requires it however I've not been able to create a failing test to cover it with. --- timecop_php7.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/timecop_php7.c b/timecop_php7.c index ff6ac6b..47b3d9e 100644 --- a/timecop_php7.c +++ b/timecop_php7.c @@ -803,22 +803,9 @@ 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); - } - 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); From f2e8c2961ccee923887fc9f3ebe51e9d2a8933c2 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 21 Jun 2021 16:25:17 +0100 Subject: [PATCH 3/4] Add comment about removal to limit future head scratching --- timecop_php7.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/timecop_php7.c b/timecop_php7.c index 47b3d9e..1c8a372 100644 --- a/timecop_php7.c +++ b/timecop_php7.c @@ -803,6 +803,8 @@ static int get_formatted_mock_time(zval *time, zval *timezone_obj, zval *retval_ get_mock_timeval(&now, NULL); + // @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); From 70ad5fda52044b49c7dc575653517bf756850e64 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 21 Jun 2021 16:27:55 +0100 Subject: [PATCH 4/4] Fix PHP 5 build --- timecop_php5.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/timecop_php5.c b/timecop_php5.c index fc021e0..f1e4d7d 100644 --- a/timecop_php5.c +++ b/timecop_php5.c @@ -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);