Skip to content

Commit

Permalink
Implement TimecopDateTime class
Browse files Browse the repository at this point in the history
  • Loading branch information
hnw committed Jun 30, 2012
1 parent 587d38a commit dc3eaa1
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 47 deletions.
13 changes: 10 additions & 3 deletions php_timecop.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extern zend_module_entry timecop_module_entry;
#include "TSRM.h"
#endif

#include <time.h>
#include "Zend/zend_interfaces.h"

PHP_MINIT_FUNCTION(timecop);
PHP_MSHUTDOWN_FUNCTION(timecop);
PHP_RINIT_FUNCTION(timecop);
Expand All @@ -52,6 +55,8 @@ PHP_FUNCTION(timecop_strtotime);
PHP_FUNCTION(timecop_strftime);
PHP_FUNCTION(timecop_gmstrftime);

PHP_METHOD(TimecopDateTime, __construct);

typedef enum timecap_mode_t {
TIMECAP_MODE_NORMAL,
TIMECAP_MODE_FREEZE,
Expand All @@ -63,12 +68,14 @@ ZEND_BEGIN_MODULE_GLOBALS(timecop)
timecap_mode_t timecap_mode;
long freezed_timestamp;
long travel_offset;
zend_class_entry *ce_DateTime;
zend_class_entry *ce_TimecopDateTime;
ZEND_END_MODULE_GLOBALS(timecop)

struct timecop_overload_def {
char *orig_func;
char *ovld_func;
char *save_func;
char *orig_name;
char *ovld_name;
char *save_name;
};

/* In every utility function you add that needs to use variables
Expand Down
26 changes: 26 additions & 0 deletions tests/overload07.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Class overloading test for datetime
--SKIPIF--
<?php
extension_loaded('timecop') or die('skip timecop not available');
$required_func = array("timecop_freeze", "timecop_orig_strtotime");
foreach ($required_func as $func_name) {
if (!function_exists($func_name)) {
die("skip $func_name() function is not available.");
}
}
$required_class = array("datetime");
foreach ($required_class as $class_name) {
if (!class_exists($class_name)) {
die("skip $class_name class is not available.");
}
}
--INI--
timecop.func_overload=1
--FILE--
<?php
timecop_freeze(timecop_orig_strtotime("2012-02-29 01:23:45"));
$dt = new DateTime();
var_dump($dt->format("Y-m-d H:i:s"));
--EXPECT--
string(19) "2012-02-29 01:23:45"
Loading

0 comments on commit dc3eaa1

Please sign in to comment.