8000 Merged pull request #8550 · php/php-src@f2b7c68 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2b7c68

Browse files
committed
Merged pull request #8550
2 parents 852e6b9 + 1af354a commit f2b7c68

11 files changed

+157
-64
lines changed

ext/date/php_date.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,7 @@ PHP_FUNCTION(getdate)
14301430
#define PHP_DATE_TIMEZONE_PER_COUNTRY 0x1000
14311431

14321432
#define PHP_DATE_PERIOD_EXCLUDE_START_DATE 0x0001
1433+
#define PHP_DATE_PERIOD_INCLUDE_END_DATE 0x0002
14331434

14341435

14351436
/* define an overloaded iterator structure */
@@ -1470,7 +1471,11 @@ static int date_period_it_has_more(zend_object_iterator *iter)
14701471
php_period_obj *object = Z_PHPPERIOD_P(&iterator->intern.data);
14711472

14721473
if (object->end) {
1473-
return object->current->sse < object->end->sse ? SUCCESS : FAILURE;
1474+
if (object->include_end_date) {
1475+
return object->current->sse <= object->< 8000 span class=pl-c1>end->sse ? SUCCESS : FAILURE;
1476+
} else {
1477+
return object->current->sse < object->end->sse ? SUCCESS : FAILURE;
1478+
}
14741479
} else {
14751480
return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE;
14761481
}
@@ -1734,6 +1739,7 @@ static void date_register_classes(void) /* {{{ */
17341739
zend_declare_class_constant_long(date_ce_period, const_name, sizeof(const_name)-1, value);
17351740

17361741
REGISTER_PERIOD_CLASS_CONST_STRING("EXCLUDE_START_DATE", PHP_DATE_PERIOD_EXCLUDE_START_DATE);
1742+
REGISTER_PERIOD_CLASS_CONST_STRING("INCLUDE_END_DATE", PHP_DATE_PERIOD_INCLUDE_END_DATE);
17371743
} /* }}} */
17381744

17391745
static zend_object *date_object_new_date(zend_class_entry *class_type) /* {{{ */
@@ -2143,6 +2149,7 @@ static zend_object *date_object_clone_period(zend_object *this_ptr) /* {{{ */
21432149
new_obj->initialized = old_obj->initialized;
21442150
new_obj->recurrences = old_obj->recurrences;
21452151
new_obj->include_start_date = old_obj->include_start_date;
2152+
new_obj->include_end_date = old_obj->include_end_date;
21462153
new_obj->start_ce = old_obj->start_ce;
21472154

21482155
if (old_obj->start) {
@@ -4567,9 +4574,10 @@ PHP_METHOD(DatePeriod, __construct)
45674574

45684575
/* options */
45694576
dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
4577+
dpobj->include_end_date = options & PHP_DATE_PERIOD_INCLUDE_END_DATE;
45704578

45714579
/* recurrrences */
4572-
dpobj->recurrences = recurrences + dpobj->include_start_date;
4580+
dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date;
45734581

45744582
dpobj->initialized = 1;
45754583
}
@@ -4653,11 +4661,11 @@ PHP_METHOD(DatePeriod, getRecurrences)
46534661

46544662
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
46554663

4656-
if (0 == dpobj->recurrences - dpobj->include_start_date) {
4664+
if (0 == dpobj->recurrences - dpobj->include_start_date - dpobj->include_end_date) {
46574665
return;
46584666
}
46594667

4660-
RETURN_LONG(dpobj->recurrences - dpobj->include_start_date);
4668+
RETURN_LONG(dpobj->recurrences - dpobj->include_start_date - dpobj->include_end_date);
46614669
}
46624670
/* }}} */
46634671

@@ -5082,6 +5090,9 @@ static void date_period_object_to_hash(php_period_obj *period_obj, HashTable *pr
50825090

50835091
ZVAL_BOOL(&zv, period_obj->include_start_date);
50845092
zend_hash_str_update(props, "include_start_date", sizeof("include_start_date")-1, &zv);
5093+
5094+
ZVAL_BOOL(&zv, period_obj->include_end_date);
5095+
zend_hash_str_update(props, "include_end_date", sizeof("include_end_date")-1, &zv);
50855096
}
50865097

50875098
static HashTable *date_object_get_properties_period(zend_object *object) /* {{{ */
@@ -5175,6 +5186,14 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
51755186
return 0;
51765187
}
51775188

5189+
ht_entry = zend_hash_str_find(myht, "include_end_date", sizeof("include_end_date")-1);
5190+
if (ht_entry &&
5191+
(Z_TYPE_P(ht_entry) == IS_FALSE || Z_TYPE_P(ht_entry) == IS_TRUE)) {
5192+
period_obj->include_end_date = (Z_TYPE_P(ht_entry) == IS_TRUE);
5193+
} else {
5194+
return 0;
5195+
}
5196+
51785197
period_obj->initialized = 1;
51795198

51805199
return 1;
@@ -5267,6 +5286,7 @@ static bool date_period_is_magic_property(zend_string *name)
52675286
{
52685287
if (zend_string_equals_literal(name, "recurrences")
52695288
|| zend_string_equals_literal(name, "include_start_date")
5289+
|| zend_string_equals_literal(name, "include_end_date")
52705290
|| zend_string_equals_literal(name, "start")
52715291
|| zend_string_equals_literal(name, "current")
52725292
|| zend_string_equals_literal(name, "end")

ext/date/php_date.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct _php_period_obj {
9393
int recurrences;
9494
bool initialized;
9595
bool include_start_date;
96+
bool include_end_date;
9697
zend_object std;
9798
};
9899

ext/date/tests/DatePeriod_serialize-001.phpt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ var_dump($d->__serialize());
2222
?>
2323
--EXPECTF--
2424
Original object:
25-
object(DatePeriod)#1 (6) {
25+
object(DatePeriod)#%d (%d) {
2626
["start"]=>
27-
object(DateTime)#2 (3) {
27+
object(DateTime)#%d (%d) {
2828
["date"]=>
2929
string(26) "2012-07-01 00:00:00.000000"
3030
["timezone_type"]=>
@@ -37,7 +37,7 @@ object(DatePeriod)#1 (6) {
3737
["end"]=>
3838
NULL
3939
["interval"]=>
40-
object(DateInterval)#3 (10) {
40+
object(DateInterval)#%d (%d) {
4141
["y"]=>
4242
int(0)
4343
["m"]=>
@@ -63,17 +63,19 @@ object(DatePeriod)#1 (6) {
6363
int(5)
6464
["include_start_date"]=>
6565
bool(true)
66+
["include_end_date"]=>
67+
bool(false)
6668
}
6769

6870

6971
Serialised object:
70-
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;}"
72+
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;}"
7173

7274

7375
Unserialised object:
74-
object(DatePeriod)#5 (6) {
76+
object(DatePeriod)#%d (%d) {
7577
["start"]=>
76-
object(DateTime)#6 (3) {
78+
object(DateTime)#%d (%d) {
7779
["date"]=>
7880
string(26) "2012-07-01 00:00:00.000000"
7981
["timezone_type"]=>
@@ -86,7 +88,7 @@ object(DatePeriod)#5 (6) {
8688
["end"]=>
8789
NULL
8890
["interval"]=>
89-
object(DateInterval)#4 (10) {
91+
object(DateInterval)#%d (%d) {
9092
["y"]=>
9193
int(0)
9294
["m"]=>
@@ -112,13 +114,15 @@ object(DatePeriod)#5 (6) {
112114
int(5)
113115
["include_start_date"]=>
114116
bool(true)
117+
["include_end_date"]=>
118+
bool(false)
115119
}
116120

117121

118122
Calling __serialize manually:
119-
array(6) {
123+
array(%d) {
120124
["start"]=>
121-
object(DateTime)#7 (3) {
125+
object(DateTime)#%d (%d) {
122126
["date"]=>
123127
string(26) "2012-07-01 00:00:00.000000"
124128
["timezone_type"]=>
@@ -131,7 +135,7 @@ array(6) {
131135
["end"]=>
132136
NULL
133137
["interval"]=>
134-
object(DateInterval)#8 (10) {
138+
object(DateInterval)#%d (%d) {
135139
["y"]=>
136140
int(0)
137141
["m"]=>
@@ -157,4 +161,6 @@ array(6) {
157161
int(5)
158162
["include_start_date"]=>
159163
bool(true)
164+
["include_end_date"]=>
165+
bool(false)
160166
}

ext/date/tests/DatePeriod_serialize-002.phpt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ foreach ( $e as $d )
3030
?>
3131
--EXPECTF--
3232
Original object:
33-
object(DatePeriod)#4 (6) {
33+
object(DatePeriod)#%d (%d) {
3434
["start"]=>
35-
object(DateTimeImmutable)#5 (3) {
35+
object(DateTimeImmutable)#%d (%d) {
3636
["date"]=>
3737
string(26) "1978-12-22 09:15:00.000000"
3838
["timezone_type"]=>
@@ -43,7 +43,7 @@ object(DatePeriod)#4 (6) {
4343
["current"]=>
4444
NULL
4545
["end"]=>
46-
object(DateTimeImmutable)#6 (3) {
46+
object(DateTimeImmutable)#%d (%d) {
4747
["date"]=>
4848
string(26) "2022-04-29 15:51:56.000000"
4949
["timezone_type"]=>
@@ -52,7 +52,7 @@ object(DatePeriod)#4 (6) {
5252
string(13) "Europe/London"
5353
}
5454
["interval"]=>
55-
object(DateInterval)#7 (10) {
55+
object(DateInterval)#%d (%d) {
5656
["y"]=>
5757
int(2)
5858
["m"]=>
@@ -78,17 +78,19 @@ object(DatePeriod)#4 (6) {
7878
int(1)
7979
["include_start_date"]=>
8080
bool(true)
81+
["include_end_date"]=>
82+
bool(false)
8183
}
8284

8385

8486
Serialised object:
85-
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;}"
87+
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;}"
8688

8789

8890
Unserialised object:
89-
object(DatePeriod)#1 (6) {
91+
object(DatePeriod)#%d (%d) {
9092
["start"]=>
91-
object(DateTimeImmutable)#2 (3) {
93+
object(DateTimeImmutable)#%d (%d) {
9294
["date"]=>
9395
string(26) "1978-12-22 09:15:00.000000"
9496
["timezone_type"]=>
@@ -99,7 +101,7 @@ object(DatePeriod)#1 (6) {
99101
["current"]=>
100102
NULL
101103
["end"]=>
102-
object(DateTimeImmutable)#8 (3) {
104+
object(DateTimeImmutable)#%d (%d) {
103105
["date"]=>
104106
string(26) "2022-04-29 15:51:56.000000"
105107
["timezone_type"]=>
@@ -108,7 +110,7 @@ object(DatePeriod)#1 (6) {
108110
string(13) "Europe/London"
109111
}
110112
["interval"]=>
111-
object(DateInterval)#9 (10) {
113+
object(DateInterval)#%d (%d) {
112114
["y"]=>
113115
int(2)
114116
["m"]=>
@@ -134,13 +136,15 @@ object(DatePeriod)#1 (6) {
134136
int(1)
135137
["include_start_date"]=>
136138
bool(true)
139+
["include_end_date"]=>
140+
bool(false)
137141
}
138142

139143

140144
Calling __serialize manually:
141-
array(6) {
145+
array(%d) {
142146
["start"]=>
143-
object(DateTimeImmutable)#10 (3) {
147+
object(DateTimeImmutable)#%d (%d) {
144148
["date"]=>
145149
string(26) "1978-12-22 09:15:00.000000"
146150
["timezone_type"]=>
@@ -151,7 +155,7 @@ array(6) {
151155
["current"]=>
152156
NULL
153157
["end"]=>
154-
object(DateTimeImmutable)#11 (3) {
158+
object(DateTimeImmutable)#%d (%d) {
155159
["date"]=>
156160
string(26) "2022-04-29 15:51:56.000000"
157161
["timezone_type"]=>
@@ -160,7 +164,7 @@ array(6) {
160164
string(13) "Europe/London"
161165
}
162166
["interval"]=>
163-
object(DateInterval)#12 (10) {
167+
object(DateInterval)#%d (%d) {
164168
["y"]=>
165169
int(2)
166170
["m"]=>
@@ -186,6 +190,8 @@ array(6) {
186190
int(1)
187191
["include_start_date"]=>
188192
bool(true)
193+
["include_end_date"]=>
194+
bool(false)
189195
}
190196

191197

0 commit comments

Comments
 (0)
0