Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,5 @@ if test "$PHP_TIMECOP" != "no"; then
AC_MSG_RESULT([$PHP_VERSION])
fi

if test "$PHP_MAJOR_VERSION" -eq 5; then
PHP_NEW_EXTENSION(timecop, timecop_php5.c tc_timeval.c, $ext_shared)
else
PHP_NEW_EXTENSION(timecop, timecop_php7.c tc_timeval.c, $ext_shared)
fi
PHP_NEW_EXTENSION(timecop, timecop.c tc_timeval.c, $ext_shared)
fi
7 changes: 1 addition & 6 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@
ARG_ENABLE("timecop", "enable timecop support", "no");

if (PHP_TIMECOP != "no") {
if (PHP_VERSION <= 5) {
EXTENSION("timecop", "timecop_php5.c tc_timeval.c");
} else {
EXTENSION("timecop", "timecop_php7.c tc_timeval.c");
}
EXTENSION("timecop", "timecop.c tc_timeval.c");
}

16 changes: 0 additions & 16 deletions tc_timeval.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ SOFTWARE.

int tc_timeval_add(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *arg2)
{
#if PHP_MAJOR_VERSION >= 7
zend_long sec, usec;
#else
long sec, usec;
#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zend_long always means 64bit integer on 64bit system, however long has 32bit length on 64bit-Windows system. This fix causes backward-compatibility problem.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usec = arg1->usec + arg2->usec;
sec = arg1->sec + arg2->sec;
if (usec < 0) {
Expand All @@ -51,11 +47,7 @@ int tc_timeval_add(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *ar
}
int tc_timeval_sub(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *arg2)
{
#if PHP_MAJOR_VERSION >= 7
zend_long sec, usec;
#else
long sec, usec;
#endif
usec = arg1->usec - arg2->usec;
sec = arg1->sec - arg2->sec;
if (usec < 0) {
Expand All @@ -75,17 +67,9 @@ int tc_timeval_sub(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *ar
return 0;
}

#if PHP_MAJOR_VERSION >= 7
int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const zend_long arg2)
#else
int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const long arg2)
#endif
{
#if PHP_MAJOR_VERSION >= 7
zend_long sec, usec;
#else
long sec, usec;
#endif
usec = arg1->usec * arg2;
sec = arg1->sec * arg2;
if (usec < 0) {
Expand Down
13 changes: 4 additions & 9 deletions tc_timeval.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,19 @@ SOFTWARE.
# define USEC_PER_SEC 1000000
#endif

#if PHP_MAJOR_VERSION < 7
typedef long zend_long;
#endif

typedef struct _tc_timeval {
#if PHP_MAJOR_VERSION >= 7
zend_long sec;
zend_long usec;
#else
long sec;
long usec;
#endif
} tc_timeval;


int tc_timeval_add(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *arg2);
int tc_timeval_sub(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *arg2);
#if PHP_MAJOR_VERSION >= 7
int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const zend_long arg2);
#else
int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const long arg2);
#endif

#endif /* TC_TIMEVAL_H */

Expand Down
34 changes: 34 additions & 0 deletions tests/issue_005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Check for issue #5 (DateTime reflection)
--SKIPIF--
<?php
$required_version = "5.3";
$required_func = array("timecop_freeze");
$required_class = array("TimecopDateTime");
include(__DIR__."/tests-skipcheck.inc.php");
--INI--
date.timezone=GMT
timecop.func_override=1
--FILE--
<?php
class Test
{
public function setCreatedAt(DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
}

$test = new Test();

$reflection = new ReflectionClass($test);
$params = $reflection->getMethod('setCreatedAt')->getParameters();

foreach ($params as $param) {
var_dump($param->getClass());
}
--EXPECT--
object(ReflectionClass)#3 (1) {
["name"]=>
string(8) "DateTime"
}
25 changes: 25 additions & 0 deletions tests/issue_030.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Check for issue #30 (DateTimeImmutable::createFromFormat with ! returns DateTime)
--SKIPIF--
<?php
$required_version = "5.5";
$required_func = array("timecop_freeze");
$required_class = array("TimecopDateTimeImmutable");
include(__DIR__."/tests-skipcheck.inc.php");
--INI--
date.timezone=GMT
timecop.func_override=1
--FILE--
<?php
$dt1 = \DateTimeImmutable::createFromFormat('!Y-m-d', '2017-10-03');
$dt2 = \DateTimeImmutable::createFromFormat('!Y-m-d', '2017-10-03');

var_dump(get_class($dt1));
var_dump($dt1->format('c'));
var_dump(get_class($dt2));
var_dump($dt2->format('c'));
--EXPECT--
string(17) "DateTimeImmutable"
string(25) "2017-10-03T00:00:00+00:00"
string(17) "DateTimeImmutable"
string(25) "2017-10-03T00:00:00+00:00"
Loading