Skip to content

Commit

Permalink
Implement timecop_idate, timecop_getdate, timecop_localtime
Browse files Browse the repository at this point in the history
  • Loading branch information
hnw committed Aug 11, 2012
1 parent 8336e53 commit 3824157
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
3 changes: 3 additions & 0 deletions php_timecop.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ PHP_FUNCTION(timecop_return);
PHP_FUNCTION(timecop_time);
PHP_FUNCTION(timecop_date);
PHP_FUNCTION(timecop_gmdate);
PHP_FUNCTION(timecop_idate);
PHP_FUNCTION(timecop_getdate);
PHP_FUNCTION(timecop_localtime);
PHP_FUNCTION(timecop_strtotime);
PHP_FUNCTION(timecop_strftime);
PHP_FUNCTION(timecop_gmstrftime);
Expand Down
19 changes: 19 additions & 0 deletions tests/overload08.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Function overloading test for idate
--SKIPIF--
<?php
extension_loaded('timecop') or die('skip timecop not available');
$required_func = array("timecop_strtotime", "timecop_freeze", "idate", "timecop_orig_idate");
foreach ($required_func as $func_name) {
if (!function_exists($func_name)) {
die("skip $func_name() function is not available.");
}
}
--INI--
timecop.func_overload=1
--FILE--
<?php
timecop_freeze(timecop_strtotime("2012-02-29 01:23:45"));
var_dump(idate("Y").idate("m").idate("d").idate("H").idate("i").idate("s"));
--EXPECT--
string(12) "201222912345"
20 changes: 20 additions & 0 deletions tests/overload09.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Function overloading test for getdate
--SKIPIF--
<?php
extension_loaded('timecop') or die('skip timecop not available');
$required_func = array("timecop_strtotime", "timecop_freeze", "getdate", "timecop_orig_getdate");
foreach ($required_func as $func_name) {
if (!function_exists($func_name)) {
die("skip $func_name() function is not available.");
}
}
--INI--
timecop.func_overload=1
--FILE--
<?php
timecop_freeze(timecop_strtotime("2012-02-29 01:23:45"));
$val = getdate();
var_dump($val['year'].$val['mon'].$val['mday'].$val['hours'].$val['minutes'].$val['seconds']);
--EXPECT--
string(12) "201222912345"
20 changes: 20 additions & 0 deletions tests/overload10.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Function overloading test for localtime
--SKIPIF--
<?php
extension_loaded('timecop') or die('skip timecop not available');
$required_func = array("timecop_strtotime", "timecop_freeze", "localtime", "timecop_orig_localtime");
foreach ($required_func as $func_name) {
if (!function_exists($func_name)) {
die("skip $func_name() function is not available.");
}
}
--INI--
timecop.func_overload=1
--FILE--
<?php
timecop_freeze(timecop_strtotime("2012-02-29 01:23:45"));
$val = localtime();
var_dump(($val[5]+1900).($val[4]+1).$val[3].$val[2].$val[1].$val[0]);
--EXPECT--
string(12) "201222912345"
35 changes: 33 additions & 2 deletions timecop.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ static const struct timecop_overload_def timecop_ovld_func[] = {
{"time", "timecop_time", "timecop_orig_time"},
{"date", "timecop_date", "timecop_orig_date"},
{"gmdate", "timecop_gmdate", "timecop_orig_gmdate"},
{"idate", "timecop_idate", "timecop_orig_idate"},
{"getdate", "timecop_getdate", "timecop_orig_getdate"},
{"localtime", "timecop_localtime", "timecop_orig_localtime"},
{"strtotime", "timecop_strtotime", "timecop_orig_strtotime"},
{"strftime", "timecop_strftime", "timecop_orig_strftime"},
{"gmstrftime", "timecop_gmstrftime", "timecop_orig_gmstrftime"},
Expand All @@ -66,6 +69,9 @@ const zend_function_entry timecop_functions[] = {
PHP_FE(timecop_time, NULL)
PHP_FE(timecop_date, NULL)
PHP_FE(timecop_gmdate, NULL)
PHP_FE(timecop_idate, NULL)
PHP_FE(timecop_getdate, NULL)
PHP_FE(timecop_localtime, NULL)
PHP_FE(timecop_strtotime, NULL)
PHP_FE(timecop_strftime, NULL)
PHP_FE(timecop_gmstrftime, NULL)
Expand Down Expand Up @@ -464,22 +470,47 @@ PHP_FUNCTION(timecop_time)
}
/* }}} */

/* {{{ proto string date(string format [, long timestamp])
/* {{{ proto string timecop_date(string format [, long timestamp])
Format a local date/time */
PHP_FUNCTION(timecop_date)
{
_timecop_call_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "date", "timecop_orig_date", 1);
}
/* }}} */

/* {{{ proto string gmdate(string format [, long timestamp])
/* {{{ proto string timecop_gmdate(string format [, long timestamp])
Format a GMT date/time */
PHP_FUNCTION(timecop_gmdate)
{
_timecop_call_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "gmdate", "timecop_orig_gmdate", 1);
}
/* }}} */

/* {{{ proto int timecop_idate(string format [, int timestamp])
Format a local time/date as integer */
PHP_FUNCTION(timecop_idate)
{
_timecop_call_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "idate", "timecop_orig_idate", 1);
}
/* }}} */

/* {{{ proto array timecop_getdate([int timestamp])
Get date/time information */
PHP_FUNCTION(timecop_getdate)
{
_timecop_call_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "getdate", "timecop_orig_getdate", 0);
}
/* }}} */

/* {{{ proto array timecop_localtime([int timestamp [, bool associative_array]])
Returns the results of the C system call localtime as an associative array if
the associative_array argument is set to 1 other wise it is a regular array */
PHP_FUNCTION(timecop_localtime)
{
_timecop_call_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "localtime", "timecop_orig_localtime", 0);
}
/* }}} */

/* {{{ proto int timecop_strtotime(string time [, int now ])
Convert string representation of date and time to a timestamp */
PHP_FUNCTION(timecop_strtotime)
Expand Down

0 comments on commit 3824157

Please sign in to comment.