-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Feature - DateTime::createFromImmutable() method #1145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
42660f3
46f22ac
d3863ae
1de1b6f
98c6567
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_date_format, 0, 0, 2) | |
ZEND_ARG_INFO(0, format) | ||
ZEND_END_ARG_INFO() | ||
|
||
ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_create_from_immutable, 0, 0, 1) | ||
ZEND_ARG_INFO(0, DateTimeImmutable) | ||
ZEND_END_ARG_INFO() | ||
|
||
ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_format, 0, 0, 1) | ||
ZEND_ARG_INFO(0, format) | ||
ZEND_END_ARG_INFO() | ||
|
@@ -466,6 +470,7 @@ const zend_function_entry date_funcs_date[] = { | |
PHP_ME(DateTime, __construct, arginfo_date_create, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC) | ||
PHP_ME(DateTime, __wakeup, NULL, ZEND_ACC_PUBLIC) | ||
PHP_ME(DateTime, __set_state, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) | ||
PHP_ME(DateTime, createFromImmutable, arginfo_date_method_create_from_immutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) | ||
PHP_ME_MAPPING(createFromFormat, date_create_from_format, arginfo_date_create_from_format, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) | ||
PHP_ME_MAPPING(getLastErrors, date_get_last_errors, arginfo_date_get_last_errors, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) | ||
PHP_ME_MAPPING(format, date_format, arginfo_date_method_format, 0) | ||
|
@@ -2832,6 +2837,34 @@ PHP_METHOD(DateTime, __wakeup) | |
} | ||
/* }}} */ | ||
|
||
/* {{{ proto DateTime::createFromImmutable(DateTimeImmutable object) | ||
Creates new DateTime object from an existing DateTimeImmutable object. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The */ should be on the previous line, at the end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just following the file's current style, which has the ending comment marker on a new line. Examples:
|
||
PHP_METHOD(DateTime, createFromImmutable) | ||
{ | ||
zval *datetimeimmutable_object = NULL; | ||
php_date_obj *new_obj = NULL; | ||
php_date_obj *old_obj = NULL; | ||
|
||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O!", &datetimeimmutable_object, date_ce_immutable) == FAILURE) { | ||
return; | ||
} | ||
|
||
php_date_instantiate(date_ce_date, return_value); | ||
old_obj = Z_PHPDATE_P(datetimeimmutable_object); | ||
new_obj = Z_PHPDATE_P(return_value); | ||
|
||
new_obj->time = timelib_time_ctor(); | ||
*new_obj->time = *old_obj->time; | ||
if (old_obj->time->tz_abbr) { | ||
new_obj->time->tz_abbr = strdup(old_obj->time->tz_abbr); | ||
} | ||
if (old_obj->time->tz_info) { | ||
new_obj->time->tz_info = old_obj->time->tz_info; | ||
} | ||
} | ||
/* }}} */ | ||
|
||
/* Helper function used to add an associative array of warnings and errors to a zval */ | ||
static void zval_from_error_container(zval *z, timelib_error_container *error) /* {{{ */ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
Tests for DateTime::createFromImmutable. | ||
--INI-- | ||
date.timezone=America/New_York | ||
--FILE-- | ||
<?php | ||
$current = "2015-03-05 07:00:16"; | ||
|
||
$i = DateTime::createFromImmutable(date_create_immutable($current)); | ||
var_dump($i); | ||
|
||
$i = DateTime::createFromImmutable(date_create($current)); | ||
var_dump($i); | ||
?> | ||
--EXPECTF-- | ||
object(DateTime)#%d (3) { | ||
["date"]=> | ||
string(26) "2015-03-05 07:00:16.000000" | ||
["timezone_type"]=> | ||
int(3) | ||
["timezone"]=> | ||
string(16) "America/New_York" | ||
} | ||
|
||
Warning: DateTime::createFromImmutable() expects parameter 1 to be DateTimeImmutable, object given in %stests%eDateTime_createFromImmutable.php on line %d | ||
NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't change the whitespace of the lines that you are not modifying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! Sorry.