com php-src: Adding a new `createFromImmutable` method to the `DateTime` class to mirror the current `DateTime::createFromMutable()`:
ext/date/php_date.c ext/date/php_date.h

From: Date: Thu, 05 Mar 2015 06:58:09 +0000
Subject: com php-src: Adding a new `createFromImmutable` method to the `DateTime` class to mirror the current `DateTime::createFromMutable()`:
ext/date/php_date.c ext/date/php_date.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85793@lists.php.net to get a copy of this message
Commit: 42660f3d6a7adf1852fc3a77fb17cecef99f9fd1 Author: Trevor Suarez <rican7@gmail.com> Thu, 5 Mar 2015 01:58:09 -0500 Parents: fe29b8134cbacf6ca07e948be4fe66813817cdad Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=42660f3d6a7adf1852fc3a77fb17cecef99f9fd1 Log: Adding a new createFromImmutable method to the DateTime class to mirror the current DateTime::createFromMutable() Changed paths: M ext/date/php_date.c M ext/date/php_date.h Diff: diff --git a/ext/date/php_date.c b/ext/date/php_date..c index ffdea3d..31d3ceb 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -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() @@ -463,9 +467,10 @@ static const zend_function_entry date_funcs_interface[] = { }; 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, __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. +*/ +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) /* {{{ */ { diff --git a/ext/date/php_date.h b/ext/date/php_date.h index ee4bac0..a423eab 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -50,6 +50,7 @@ PHP_FUNCTION(getdate); PHP_METHOD(DateTime, __construct); PHP_METHOD(DateTime, __wakeup); PHP_METHOD(DateTime, __set_state); +PHP_METHOD(DateTime, createFromImmutable); PHP_FUNCTION(date_create); PHP_FUNCTION(date_create_immutable); PHP_FUNCTION(date_create_from_format);

« previous php.cvs (#85793) next »