From c0c801d23813f6d485e64ea866654ff0798517e0 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 13 May 2022 14:20:05 +0100 Subject: [PATCH 1/3] Fixed bug #52015 (Allow including end date in DatePeriod iterations) --- ext/date/php_date.c | 11 +++++++++-- ext/date/php_date.h | 1 + ext/date/tests/date_period_include_end.phpt | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 ext/date/tests/date_period_include_end.phpt diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 96cd22129c10a..7ac02bf733c18 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1430,6 +1430,7 @@ PHP_FUNCTION(getdate) #define PHP_DATE_TIMEZONE_PER_COUNTRY 0x1000 #define PHP_DATE_PERIOD_EXCLUDE_START_DATE 0x0001 +#define PHP_DATE_PERIOD_INCLUDE_END_DATE 0x0002 /* define an overloaded iterator structure */ @@ -1470,7 +1471,11 @@ static int date_period_it_has_more(zend_object_iterator *iter) php_period_obj *object = Z_PHPPERIOD_P(&iterator->intern.data); if (object->end) { - return object->current->sse < object->end->sse ? SUCCESS : FAILURE; + if (object->include_end_date) { + return object->current->sse <= object->end->sse ? SUCCESS : FAILURE; + } else { + return object->current->sse < object->end->sse ? SUCCESS : FAILURE; + } } else { return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE; } @@ -1734,6 +1739,7 @@ static void date_register_classes(void) /* {{{ */ zend_declare_class_constant_long(date_ce_period, const_name, sizeof(const_name)-1, value); REGISTER_PERIOD_CLASS_CONST_STRING("EXCLUDE_START_DATE", PHP_DATE_PERIOD_EXCLUDE_START_DATE); + REGISTER_PERIOD_CLASS_CONST_STRING("INCLUDE_END_DATE", PHP_DATE_PERIOD_INCLUDE_END_DATE); } /* }}} */ static zend_object *date_object_new_date(zend_class_entry *class_type) /* {{{ */ @@ -4567,9 +4573,10 @@ PHP_METHOD(DatePeriod, __construct) /* options */ dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE); + dpobj->include_end_date = options & PHP_DATE_PERIOD_INCLUDE_END_DATE; /* recurrrences */ - dpobj->recurrences = recurrences + dpobj->include_start_date; + dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date; dpobj->initialized = 1; } diff --git a/ext/date/php_date.h b/ext/date/php_date.h index d18529f10d30f..aa6883a5e4679 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -93,6 +93,7 @@ struct _php_period_obj { int recurrences; bool initialized; bool include_start_date; + int include_end_date; zend_object std; }; diff --git a/ext/date/tests/date_period_include_end.phpt b/ext/date/tests/date_period_include_end.phpt new file mode 100644 index 0000000000000..c96e279465367 --- /dev/null +++ b/ext/date/tests/date_period_include_end.phpt @@ -0,0 +1,19 @@ +--TEST-- +DatePeriod::INCLUDE_END_DATE +--FILE-- +format('Y-m-d') . "\n"; +} +?> +--EXPECT-- +2010-06-07 +2010-06-08 +2010-06-09 +2010-06-10 + From 4f1b8f4828601396938a3ba7b7d21722981e2167 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 20 May 2022 10:34:34 +0100 Subject: [PATCH 2/3] Add serialisation support for the new 'include_end_date' property --- ext/date/php_date.c | 17 +++++++++-- ext/date/php_date.h | 2 +- ext/date/tests/DatePeriod_serialize-001.phpt | 26 ++++++++++------ ext/date/tests/DatePeriod_serialize-002.phpt | 32 ++++++++++++-------- ext/date/tests/DatePeriod_serialize-003.phpt | 32 ++++++++++++-------- ext/date/tests/DatePeriod_serialize-004.phpt | 30 ++++++++++-------- ext/date/tests/DatePeriod_set_state.phpt | 6 ++-- ext/date/tests/bug52113.phpt | 12 +++++--- ext/date/tests/bug53437_var0.phpt | 16 ++++++---- 9 files changed, 110 insertions(+), 63 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 7ac02bf733c18..41521e27d0049 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2149,6 +2149,7 @@ static zend_object *date_object_clone_period(zend_object *this_ptr) /* {{{ */ new_obj->initialized = old_obj->initialized; new_obj->recurrences = old_obj->recurrences; new_obj->include_start_date = old_obj->include_start_date; + new_obj->include_end_date = old_obj->include_end_date; new_obj->start_ce = old_obj->start_ce; if (old_obj->start) { @@ -4660,11 +4661,11 @@ PHP_METHOD(DatePeriod, getRecurrences) dpobj = Z_PHPPERIOD_P(ZEND_THIS); - if (0 == dpobj->recurrences - dpobj->include_start_date) { + if (0 == dpobj->recurrences - dpobj->include_start_date - dpobj->include_end_date) { return; } - RETURN_LONG(dpobj->recurrences - dpobj->include_start_date); + RETURN_LONG(dpobj->recurrences - dpobj->include_start_date - dpobj->include_end_date); } /* }}} */ @@ -5089,6 +5090,9 @@ static void date_period_object_to_hash(php_period_obj *period_obj, HashTable *pr ZVAL_BOOL(&zv, period_obj->include_start_date); zend_hash_str_update(props, "include_start_date", sizeof("include_start_date")-1, &zv); + + ZVAL_BOOL(&zv, period_obj->include_end_date); + zend_hash_str_update(props, "include_end_date", sizeof("include_end_date")-1, &zv); } static HashTable *date_object_get_properties_period(zend_object *object) /* {{{ */ @@ -5182,6 +5186,14 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has return 0; } + ht_entry = zend_hash_str_find(myht, "include_end_date", sizeof("include_end_date")-1); + if (ht_entry && + (Z_TYPE_P(ht_entry) == IS_FALSE || Z_TYPE_P(ht_entry) == IS_TRUE)) { + period_obj->include_end_date = (Z_TYPE_P(ht_entry) == IS_TRUE); + } else { + return 0; + } + period_obj->initialized = 1; return 1; @@ -5274,6 +5286,7 @@ static bool date_period_is_magic_property(zend_string *name) { if (zend_string_equals_literal(name, "recurrences") || zend_string_equals_literal(name, "include_start_date") + || zend_string_equals_literal(name, "include_end_date") || zend_string_equals_literal(name, "start") || zend_string_equals_literal(name, "current") || zend_string_equals_literal(name, "end") diff --git a/ext/date/php_date.h b/ext/date/php_date.h index aa6883a5e4679..129f3617617a7 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -93,7 +93,7 @@ struct _php_period_obj { int recurrences; bool initialized; bool include_start_date; - int include_end_date; + bool include_end_date; zend_object std; }; diff --git a/ext/date/tests/DatePeriod_serialize-001.phpt b/ext/date/tests/DatePeriod_serialize-001.phpt index 0f555ab425145..5bfc94578d83e 100644 --- a/ext/date/tests/DatePeriod_serialize-001.phpt +++ b/ext/date/tests/DatePeriod_serialize-001.phpt @@ -22,9 +22,9 @@ var_dump($d->__serialize()); ?> --EXPECTF-- Original object: -object(DatePeriod)#1 (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTime)#2 (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2012-07-01 00:00:00.000000" ["timezone_type"]=> @@ -37,7 +37,7 @@ object(DatePeriod)#1 (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#3 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -63,17 +63,19 @@ object(DatePeriod)#1 (6) { int(5) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } Serialised object: -string(411) "O:10:"DatePeriod":6:{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;}" +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;}" Unserialised object: -object(DatePeriod)#5 (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTime)#6 (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2012-07-01 00:00:00.000000" ["timezone_type"]=> @@ -86,7 +88,7 @@ object(DatePeriod)#5 (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#4 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -112,13 +114,15 @@ object(DatePeriod)#5 (6) { int(5) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } Calling __serialize manually: -array(6) { +array(%d) { ["start"]=> - object(DateTime)#7 (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2012-07-01 00:00:00.000000" ["timezone_type"]=> @@ -131,7 +135,7 @@ array(6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#8 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -157,4 +161,6 @@ array(6) { int(5) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } diff --git a/ext/date/tests/DatePeriod_serialize-002.phpt b/ext/date/tests/DatePeriod_serialize-002.phpt index 7e9d3e62dae54..d87bcd9a866db 100644 --- a/ext/date/tests/DatePeriod_serialize-002.phpt +++ b/ext/date/tests/DatePeriod_serialize-002.phpt @@ -30,9 +30,9 @@ foreach ( $e as $d ) ?> --EXPECTF-- Original object: -object(DatePeriod)#4 (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTimeImmutable)#5 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -43,7 +43,7 @@ object(DatePeriod)#4 (6) { ["current"]=> NULL ["end"]=> - object(DateTimeImmutable)#6 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "2022-04-29 15:51:56.000000" ["timezone_type"]=> @@ -52,7 +52,7 @@ object(DatePeriod)#4 (6) { string(13) "Europe/London" } ["interval"]=> - object(DateInterval)#7 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -78,17 +78,19 @@ object(DatePeriod)#4 (6) { int(1) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } Serialised object: -string(565) "O:10:"DatePeriod":6:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";N;s:3:"end";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2022-04-29 15:51:56.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/London";}s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:2;s:1:"m";i:6;s:1:"d";i:0;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:1;s:18:"include_start_date";b:1;}" +string(%d) "O:10:"DatePeriod":7:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";N;s:3:"end";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2022-04-29 15:51:56.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/London";}s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:2;s:1:"m";i:6;s:1:"d";i:0;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:1;s:18:"include_start_date";b:1;s:16:"include_end_date";b:0;}" Unserialised object: -object(DatePeriod)#1 (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTimeImmutable)#2 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -99,7 +101,7 @@ object(DatePeriod)#1 (6) { ["current"]=> NULL ["end"]=> - object(DateTimeImmutable)#8 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "2022-04-29 15:51:56.000000" ["timezone_type"]=> @@ -108,7 +110,7 @@ object(DatePeriod)#1 (6) { string(13) "Europe/London" } ["interval"]=> - object(DateInterval)#9 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -134,13 +136,15 @@ object(DatePeriod)#1 (6) { int(1) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } Calling __serialize manually: -array(6) { +array(%d) { ["start"]=> - object(DateTimeImmutable)#10 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -151,7 +155,7 @@ array(6) { ["current"]=> NULL ["end"]=> - object(DateTimeImmutable)#11 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "2022-04-29 15:51:56.000000" ["timezone_type"]=> @@ -160,7 +164,7 @@ array(6) { string(13) "Europe/London" } ["interval"]=> - object(DateInterval)#12 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -186,6 +190,8 @@ array(6) { int(1) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } diff --git a/ext/date/tests/DatePeriod_serialize-003.phpt b/ext/date/tests/DatePeriod_serialize-003.phpt index ada8c7478f586..af52e5642b41e 100644 --- a/ext/date/tests/DatePeriod_serialize-003.phpt +++ b/ext/date/tests/DatePeriod_serialize-003.phpt @@ -30,9 +30,9 @@ foreach ( $e as $d ) ?> --EXPECTF-- Original object: -object(DatePeriod)#4 (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTimeImmutable)#5 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -43,7 +43,7 @@ object(DatePeriod)#4 (6) { ["current"]=> NULL ["end"]=> - object(DateTimeImmutable)#6 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "2022-04-29 15:51:56.000000" ["timezone_type"]=> @@ -52,7 +52,7 @@ object(DatePeriod)#4 (6) { string(13) "Europe/London" } ["interval"]=> - object(DateInterval)#7 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -78,17 +78,19 @@ object(DatePeriod)#4 (6) { int(0) ["include_start_date"]=> bool(false) + ["include_end_date"]=> + bool(false) } Serialised object: -string(565) "O:10:"DatePeriod":6:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";N;s:3:"end";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2022-04-29 15:51:56.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/London";}s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:2;s:1:"m";i:6;s:1:"d";i:0;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:0;s:18:"include_start_date";b:0;}" +string(%d) "O:10:"DatePeriod":7:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";N;s:3:"end";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"2022-04-29 15:51:56.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/London";}s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:2;s:1:"m";i:6;s:1:"d";i:0;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:0;s:18:"include_start_date";b:0;s:16:"include_end_date";b:0;}" Unserialised object: -object(DatePeriod)#1 (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTimeImmutable)#2 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -99,7 +101,7 @@ object(DatePeriod)#1 (6) { ["current"]=> NULL ["end"]=> - object(DateTimeImmutable)#8 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "2022-04-29 15:51:56.000000" ["timezone_type"]=> @@ -108,7 +110,7 @@ object(DatePeriod)#1 (6) { string(13) "Europe/London" } ["interval"]=> - object(DateInterval)#9 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -134,13 +136,15 @@ object(DatePeriod)#1 (6) { int(0) ["include_start_date"]=> bool(false) + ["include_end_date"]=> + bool(false) } Calling __serialize manually: -array(6) { +array(%d) { ["start"]=> - object(DateTimeImmutable)#10 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -151,7 +155,7 @@ array(6) { ["current"]=> NULL ["end"]=> - object(DateTimeImmutable)#11 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "2022-04-29 15:51:56.000000" ["timezone_type"]=> @@ -160,7 +164,7 @@ array(6) { string(13) "Europe/London" } ["interval"]=> - object(DateInterval)#12 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(2) ["m"]=> @@ -186,6 +190,8 @@ array(6) { int(0) ["include_start_date"]=> bool(false) + ["include_end_date"]=> + bool(false) } diff --git a/ext/date/tests/DatePeriod_serialize-004.phpt b/ext/date/tests/DatePeriod_serialize-004.phpt index fd62c5e2b7630..f3e8b1156e9be 100644 --- a/ext/date/tests/DatePeriod_serialize-004.phpt +++ b/ext/date/tests/DatePeriod_serialize-004.phpt @@ -35,9 +35,9 @@ foreach ( $p as $d ) ?> --EXPECTF-- Original object: -object(DatePeriod)#3 (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTimeImmutable)#4 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -50,7 +50,7 @@ object(DatePeriod)#3 (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#5 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -76,6 +76,8 @@ object(DatePeriod)#3 (6) { int(7) ["include_start_date"]=> bool(false) + ["include_end_date"]=> + bool(false) } @@ -90,13 +92,13 @@ Iterate of object: Serialised object: -string(568) "O:10:"DatePeriod":6:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1979-08-06 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:1;s:1:"d";i:0;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:7;s:18:"include_start_date";b:0;}" +string(%d) "O:10:"DatePeriod":7:{s:5:"start";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1978-12-22 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:7:"current";O:17:"DateTimeImmutable":3:{s:4:"date";s:26:"1979-08-06 09:15:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:16:"Europe/Amsterdam";}s:3:"end";N;s:8:"interval";O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:1;s:1:"d";i:0;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:7;s:18:"include_start_date";b:0;s:16:"include_end_date";b:0;}" Unserialised object: -object(DatePeriod)#1 (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTimeImmutable)#6 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -105,7 +107,7 @@ object(DatePeriod)#1 (6) { string(16) "Europe/Amsterdam" } ["current"]=> - object(DateTimeImmutable)#8 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1979-08-06 09:15:00.000000" ["timezone_type"]=> @@ -116,7 +118,7 @@ object(DatePeriod)#1 (6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#9 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -142,13 +144,15 @@ object(DatePeriod)#1 (6) { int(7) ["include_start_date"]=> bool(false) + ["include_end_date"]=> + bool(false) } Calling __serialize manually: -array(6) { +array(%d) { ["start"]=> - object(DateTimeImmutable)#10 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1978-12-22 09:15:00.000000" ["timezone_type"]=> @@ -157,7 +161,7 @@ array(6) { string(16) "Europe/Amsterdam" } ["current"]=> - object(DateTimeImmutable)#11 (3) { + object(DateTimeImmutable)#%d (%d) { ["date"]=> string(26) "1979-08-06 09:15:00.000000" ["timezone_type"]=> @@ -168,7 +172,7 @@ array(6) { ["end"]=> NULL ["interval"]=> - object(DateInterval)#12 (10) { + object(DateInterval)#%d (%d) { ["y"]=> int(0) ["m"]=> @@ -194,6 +198,8 @@ array(6) { int(7) ["include_start_date"]=> bool(false) + ["include_end_date"]=> + bool(false) } diff --git a/ext/date/tests/DatePeriod_set_state.phpt b/ext/date/tests/DatePeriod_set_state.phpt index de41eac50a5f9..b7d537e98570b 100644 --- a/ext/date/tests/DatePeriod_set_state.phpt +++ b/ext/date/tests/DatePeriod_set_state.phpt @@ -19,9 +19,9 @@ var_dump($datePeriodObjectNew); ?> --EXPECTF-- -object(DatePeriod)#%d (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTime)#%d (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2017-10-06 23:30:00.000000" ["timezone_type"]=> @@ -60,4 +60,6 @@ object(DatePeriod)#%d (6) { int(25) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt index 2e02195bd1d1a..74c8157fcad46 100644 --- a/ext/date/tests/bug52113.phpt +++ b/ext/date/tests/bug52113.phpt @@ -89,9 +89,9 @@ string(164) "O:12:"DateInterval":10:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h" ["from_string"]=> bool(false) } -object(DatePeriod)#%d (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTime)#%d (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2003-01-02 08:00:00.000000" ["timezone_type"]=> @@ -130,6 +130,8 @@ object(DatePeriod)#%d (6) { int(3) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } object(DateInterval)#%d (%d) { ["y"]=> @@ -153,9 +155,9 @@ object(DateInterval)#%d (%d) { ["from_string"]=> bool(false) } -object(DatePeriod)#%d (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTime)#%d (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2003-01-02 08:00:00.000000" ["timezone_type"]=> @@ -194,4 +196,6 @@ object(DatePeriod)#%d (6) { int(3) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } diff --git a/ext/date/tests/bug53437_var0.phpt b/ext/date/tests/bug53437_var0.phpt index 36b6c317177f2..9ae257a61b0fe 100644 --- a/ext/date/tests/bug53437_var0.phpt +++ b/ext/date/tests/bug53437_var0.phpt @@ -28,9 +28,9 @@ Original: 2010-01-02 00:00:00 2010-01-03 00:00:00 -object(DatePeriod)#%d (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTime)#%d (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2010-01-01 00:00:00.000000" ["timezone_type"]=> @@ -39,7 +39,7 @@ object(DatePeriod)#%d (6) { string(3) "UTC" } ["current"]=> - object(DateTime)#%d (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2010-01-04 00:00:00.000000" ["timezone_type"]=> @@ -76,10 +76,12 @@ object(DatePeriod)#%d (6) { int(3) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } -object(DatePeriod)#%d (6) { +object(DatePeriod)#%d (%d) { ["start"]=> - object(DateTime)#%d (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2010-01-01 00:00:00.000000" ["timezone_type"]=> @@ -88,7 +90,7 @@ object(DatePeriod)#%d (6) { string(3) "UTC" } ["current"]=> - object(DateTime)#%d (3) { + object(DateTime)#%d (%d) { ["date"]=> string(26) "2010-01-04 00:00:00.000000" ["timezone_type"]=> @@ -125,6 +127,8 @@ object(DatePeriod)#%d (6) { int(3) ["include_start_date"]=> bool(true) + ["include_end_date"]=> + bool(false) } Unserialized: 2010-01-01 00:00:00 From 1af354a659202d3eb8c7b6fe1bd7b2265329c4aa Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 20 May 2022 10:34:53 +0100 Subject: [PATCH 3/3] Add extra test case that hase both EXCLUDE_START_DATE and INCLUDE_END_DATE --- ..._period_exclude_start_and_include_end.phpt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ext/date/tests/date_period_exclude_start_and_include_end.phpt diff --git a/ext/date/tests/date_period_exclude_start_and_include_end.phpt b/ext/date/tests/date_period_exclude_start_and_include_end.phpt new file mode 100644 index 0000000000000..6238f67073519 --- /dev/null +++ b/ext/date/tests/date_period_exclude_start_and_include_end.phpt @@ -0,0 +1,19 @@ +--TEST-- +DatePeriod::EXCLUDE_START_DATE|DatePeriod::INCLUDE_END_DATE +--FILE-- +format('Y-m-d') . "\n"; +} +?> +--EXPECT-- +2010-06-08 +2010-06-09 +2010-06-10 +