mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge remote-tracking branch 'derickr/create-from-iso-string-immutable'
This commit is contained in:
commit
7273349a1f
3 changed files with 14 additions and 11 deletions
|
@ -4270,7 +4270,8 @@ static bool date_interval_initialize(timelib_rel_time **rt, /*const*/ char *form
|
||||||
return retval;
|
return retval;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
static int date_interval_compare_objects(zval *o1, zval *o2) {
|
static int date_interval_compare_objects(zval *o1, zval *o2)
|
||||||
|
{
|
||||||
ZEND_COMPARE_OBJECTS_FALLBACK(o1, o2);
|
ZEND_COMPARE_OBJECTS_FALLBACK(o1, o2);
|
||||||
/* There is no well defined way to compare intervals like P1M and P30D, which may compare
|
/* There is no well defined way to compare intervals like P1M and P30D, which may compare
|
||||||
* smaller, equal or greater depending on the point in time at which the interval starts. As
|
* smaller, equal or greater depending on the point in time at which the interval starts. As
|
||||||
|
@ -4843,7 +4844,8 @@ static bool date_period_initialize(timelib_time **st, timelib_time **et, timelib
|
||||||
return retval;
|
return retval;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
static bool date_period_init_iso8601_string(php_period_obj *dpobj, char *isostr, size_t isostr_len, zend_long options, zend_long *recurrences) {
|
static bool date_period_init_iso8601_string(php_period_obj *dpobj, zend_class_entry* base_ce, char *isostr, size_t isostr_len, zend_long options, zend_long *recurrences)
|
||||||
|
{
|
||||||
if (!date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), recurrences, isostr, isostr_len)) {
|
if (!date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), recurrences, isostr, isostr_len)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -4873,12 +4875,13 @@ static bool date_period_init_iso8601_string(php_period_obj *dpobj, char *isostr,
|
||||||
if (dpobj->end) {
|
if (dpobj->end) {
|
||||||
timelib_update_ts(dpobj->end, NULL);
|
timelib_update_ts(dpobj->end, NULL);
|
||||||
}
|
}
|
||||||
dpobj->start_ce = date_ce_date;
|
dpobj->start_ce = base_ce;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool date_period_init_finish(php_period_obj *dpobj, zend_long options, zend_long recurrences) {
|
static bool date_period_init_finish(php_period_obj *dpobj, zend_long options, zend_long recurrences)
|
||||||
|
{
|
||||||
if (dpobj->end == NULL && recurrences < 1) {
|
if (dpobj->end == NULL && recurrences < 1) {
|
||||||
zend_string *func = get_active_function_or_method_name();
|
zend_string *func = get_active_function_or_method_name();
|
||||||
zend_throw_exception_ex(date_ce_date_malformed_period_string_exception, 0, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
|
zend_throw_exception_ex(date_ce_date_malformed_period_string_exception, 0, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
|
||||||
|
@ -4916,7 +4919,7 @@ PHP_METHOD(DatePeriod, createFromISO8601String)
|
||||||
|
|
||||||
dpobj->current = NULL;
|
dpobj->current = NULL;
|
||||||
|
|
||||||
if (!date_period_init_iso8601_string(dpobj, isostr, isostr_len, options, &recurrences)) {
|
if (!date_period_init_iso8601_string(dpobj, date_ce_immutable, isostr, isostr_len, options, &recurrences)) {
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4949,7 +4952,7 @@ PHP_METHOD(DatePeriod, __construct)
|
||||||
dpobj->current = NULL;
|
dpobj->current = NULL;
|
||||||
|
|
||||||
if (isostr) {
|
if (isostr) {
|
||||||
if (!date_period_init_iso8601_string(dpobj, isostr, isostr_len, options, &recurrences)) {
|
if (!date_period_init_iso8601_string(dpobj, date_ce_date, isostr, isostr_len, options, &recurrences)) {
|
||||||
RETURN_THROWS();
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,7 +23,7 @@ try {
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
object(MyDatePeriod)#1 (7) {
|
object(MyDatePeriod)#1 (7) {
|
||||||
["start"]=>
|
["start"]=>
|
||||||
object(DateTime)#2 (3) {
|
object(DateTimeImmutable)#2 (3) {
|
||||||
["date"]=>
|
["date"]=>
|
||||||
string(26) "2012-07-01 00:00:00.000000"
|
string(26) "2012-07-01 00:00:00.000000"
|
||||||
["timezone_type"]=>
|
["timezone_type"]=>
|
||||||
|
|
|
@ -24,7 +24,7 @@ var_dump($d->__serialize());
|
||||||
Original object:
|
Original object:
|
||||||
object(DatePeriod)#%d (%d) {
|
object(DatePeriod)#%d (%d) {
|
||||||
["start"]=>
|
["start"]=>
|
||||||
object(DateTime)#%d (%d) {
|
object(DateTimeImmutable)#%d (%d) {
|
||||||
["date"]=>
|
["date"]=>
|
||||||
string(26) "2012-07-01 00:00:00.000000"
|
string(26) "2012-07-01 00:00:00.000000"
|
||||||
["timezone_type"]=>
|
["timezone_type"]=>
|
||||||
|
@ -69,13 +69,13 @@ object(DatePeriod)#%d (%d) {
|
||||||
|
|
||||||
|
|
||||||
Serialised object:
|
Serialised object:
|
||||||
string(%d) "O:10:"DatePeriod":7:{s:5:"start";O:8:"DateTime":3:{s:4:"date";s:26:"2012-07-01 00:00:00.000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}s:7:"current";N;s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:7;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:5;s:18:"include_start_date";b:1;s:16:"include_end_date";b:0;}"
|
string(%d) "O:10:"DatePeriod":7:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2012-07-01 00:00:00.000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}s:7:"current";N;s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:7;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;}s:11:"recurrences";i:5;s:18:"include_start_date";b:1;s:16:"include_end_date";b:0;}"
|
||||||
|
|
||||||
|
|
||||||
Unserialised object:
|
Unserialised object:
|
||||||
object(DatePeriod)#%d (%d) {
|
object(DatePeriod)#%d (%d) {
|
||||||
["start"]=>
|
["start"]=>
|
||||||
object(DateTime)#%d (%d) {
|
object(DateTimeImmutable)#%d (%d) {
|
||||||
["date"]=>
|
["date"]=>
|
||||||
string(26) "2012-07-01 00:00:00.000000"
|
string(26) "2012-07-01 00:00:00.000000"
|
||||||
["timezone_type"]=>
|
["timezone_type"]=>
|
||||||
|
@ -122,7 +122,7 @@ object(DatePeriod)#%d (%d) {
|
||||||
Calling __serialize manually:
|
Calling __serialize manually:
|
||||||
array(%d) {
|
array(%d) {
|
||||||
["start"]=>
|
["start"]=>
|
||||||
object(DateTime)#%d (%d) {
|
object(DateTimeImmutable)#%d (%d) {
|
||||||
["date"]=>
|
["date"]=>
|
||||||
string(26) "2012-07-01 00:00:00.000000"
|
string(26) "2012-07-01 00:00:00.000000"
|
||||||
["timezone_type"]=>
|
["timezone_type"]=>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue