Skip to content

Commit

Permalink
Change version to 1.0.4 / Add some tests / Rewrite changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
hnw committed Mar 12, 2013
1 parent 93118d8 commit ce0214b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ var_dump(strtotime("+100000 sec")); // int(10000)

## CHANGELOG

###version 1.0.4, 2013/03/11
- Fixed SIGSEGV in TimecopDateTime::__construct() called with NULL as 1st argument

###version 1.0.3, 2013/03/09

- Fixed the time traveling implementation for TimecopDateTime::__construct()
Expand All @@ -79,7 +82,8 @@ var_dump(strtotime("+100000 sec")); // int(10000)

###version 1.0.1, 2013/03/04

- Fixed time traveling bug about TimecopDateTime::__construct() when it is called with 1 or 2 arguments
- Implement time traveling feature for TimecopDateTime::__construct() with 1 or 2 arguments
- The previous version works collectly only for no arguments calling: "new TimecopDateTime()"

###version 1.0.0, 2012/11/21

Expand Down
2 changes: 1 addition & 1 deletion php_timecop.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef PHP_TIMECOP_H
#define PHP_TIMECOP_H

#define PHP_TIMECOP_VERSION "1.0.3"
#define PHP_TIMECOP_VERSION "1.0.4"

extern zend_module_entry timecop_module_entry;
#define phpext_timecop_ptr &timecop_module_entry
Expand Down
24 changes: 24 additions & 0 deletions tests/011.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Check for serialize/unserialize TimecopDateTime instance
--SKIPIF--
<?php
extension_loaded('timecop') or die('skip timecop not available');
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
die("skip requires PHP >= 5.3.0");
}
$required_class = array("timecopdatetime");
foreach ($required_class as $class_name) {
if (!class_exists($class_name)) {
die("skip $class_name class is not available.");
}
}
--INI--
date.timezone=America/Los_Angeles
timecop.func_override=0
--FILE--
<?php
$dt1 = new TimecopDateTime("2012-01-01 12:00:00 GMT");
$dt2 = unserialize(serialize($dt1));
var_dump($dt2->format("c"));
--EXPECT--
string(25) "2012-01-01T12:00:00+00:00"
18 changes: 9 additions & 9 deletions timecop.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ zend_module_entry timecop_module_entry = {
PHP_RSHUTDOWN(timecop),
PHP_MINFO(timecop),
#if ZEND_MODULE_API_NO >= 20010901
"0.1",
PHP_TIMECOP_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
Expand Down Expand Up @@ -600,22 +600,22 @@ static int fix_datetime_timestamp(zval **datetime_obj, zval *time TSRMLS_DC)
if (time == NULL) {
time = &now;
} else {
zval time_str;
time_str = *time;
zval_copy_ctor(&time_str);
convert_to_string(&time_str);
if (Z_STRLEN(time_str) == 0) {
time = &now;
zval *len;
zend_call_method_with_1_params(NULL, NULL, NULL, "strlen", &len, time);
if (len) {
if (Z_LVAL_P(len) == 0) {
time = &now;
}
zval_ptr_dtor(&len);
}
zval_dtor(&time_str);
}

zend_call_method_with_0_params(datetime_obj, Z_OBJCE_PP(datetime_obj), NULL, "gettimestamp", &orig_timestamp);
zend_call_method_with_1_params(NULL, NULL, NULL, "timecop_strtotime", &fixed_timestamp, time);

if (Z_TYPE_P(fixed_timestamp) == IS_BOOL && Z_BVAL_P(fixed_timestamp) == 0) {
// timecop_strtotime($time) === false
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse time string '%s'", Z_STRVAL_P(time));
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse time string '%s': giving up time traveling", Z_STRVAL_P(time));
} else if (Z_LVAL_P(orig_timestamp) != Z_LVAL_P(fixed_timestamp)) {
zend_call_method_with_1_params(datetime_obj, Z_OBJCE_PP(datetime_obj), NULL, "settimestamp", NULL, fixed_timestamp);
}
Expand Down

0 comments on commit ce0214b

Please sign in to comment.