Skip to content

Commit c8a6a8a

Browse files
committed
Rename have_special_relative to from_string, fix serialisation constraint, and reorder fields
1 parent c280121 commit c8a6a8a

30 files changed

+108
-97
lines changed

ext/date/php_date.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,11 +2077,6 @@ static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTabl
20772077
PHP_DATE_INTERVAL_ADD_PROPERTY("s", s);
20782078
ZVAL_DOUBLE(&zv, (double)intervalobj->diff->us / 1000000.0);
20792079
zend_hash_str_update(props, "f", sizeof("f") - 1, &zv);
2080-
if (include_fakes) {
2081-
PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday);
2082-
PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior);
2083-
PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of);
2084-
}
20852080
PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert);
20862081
if (intervalobj->diff->days != -99999) {
20872082
PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
@@ -2090,12 +2085,19 @@ static void date_interval_object_to_hash(php_interval_obj *intervalobj, HashTabl
20902085
zend_hash_str_update(props, "days", sizeof("days")-1, &zv);
20912086
}
20922087
if (include_fakes) {
2088+
PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday);
2089+
PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior);
2090+
PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of);
20932091
PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type);
20942092
PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount);
20952093
PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative);
2094+
PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative);
2095+
ZVAL_LONG(&zv, (zend_long)intervalobj->civil_or_wall);
2096+
zend_hash_str_update(props, "civil_or_wall", strlen("civil_or_wall"), &zv);
20962097
}
2097-
/* Records whether this is a special relative interval that can't be serialized */
2098-
PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative);
2098+
/* Records whether this is a special relative interval that needs to be recreated from a string */
2099+
ZVAL_BOOL(&zv, (zend_bool)intervalobj->from_string);
2100+
zend_hash_str_update(props, "from_string", strlen("from_string"), &zv);
20992101

21002102
#undef PHP_DATE_INTERVAL_ADD_PROPERTY
21012103
}
@@ -3095,7 +3097,7 @@ static void php_date_sub(zval *object, zval *interval, zval *return_value) /* {{
30953097
intobj = Z_PHPINTERVAL_P(interval);
30963098
DATE_CHECK_INITIALIZED(intobj->initialized, DateInterval);
30973099

3098-
if (intobj->diff->have_special_relative) {
3100+
if (intobj->diff->have_weekday_relative || intobj->diff->have_special_relative) {
30993101
php_error_docref(NULL, E_WARNING, "Only non-special relative time specifications are supported for subtraction");
31003102
return;
31013103
}
@@ -4223,7 +4225,7 @@ PHP_METHOD(DateInterval, __serialize)
42234225
intervalobj = Z_PHPINTERVAL_P(object);
42244226
DATE_CHECK_INITIALIZED(intervalobj->initialized, DateInterval);
42254227

4226-
if (intervalobj->diff->have_special_relative) {
4228+
if (intervalobj->diff->have_weekday_relative || intervalobj->diff->have_special_relative) {
42274229
zend_throw_exception_ex(NULL, 0, "Serializing special relative time specifications is not supported");
42284230
}
42294231

ext/date/php_date.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static inline php_timezone_obj *php_timezone_obj_from_obj(zend_object *obj) {
7272
struct _php_interval_obj {
7373
timelib_rel_time *diff;
7474
int civil_or_wall;
75+
bool from_string;
7576
bool initialized;
7677
zend_object std;
7778
};

ext/date/tests/DateInterval_serialize-001.phpt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ object(DateInterval)#1 (10) {
4040
int(0)
4141
["days"]=>
4242
bool(false)
43-
["have_special_relative"]=>
44-
int(0)
43+
["from_string"]=>
44+
bool(false)
4545
}
4646

4747

4848
Serialised object:
49-
string(332) "O:12:"DateInterval":16:{s:1:"y";i:2;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i:6;s:1:"i";i:8;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}"
49+
string(380) "O:12:"DateInterval":18:{s:1:"y";i:2;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i:6;s:1:"i";i:8;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:2;s:11:"from_string";b:0;}"
5050

5151

5252
Unserialised object:
@@ -69,13 +69,13 @@ object(DateInterval)#2 (10) {
6969
int(0)
7070
["days"]=>
7171
bool(false)
72-
["have_special_relative"]=>
73-
int(0)
72+
["from_string"]=>
73+
bool(false)
7474
}
7575

7676

7777
Calling __serialize manually:
78-
array(16) {
78+
array(%d) {
7979
["y"]=>
8080
int(2)
8181
["m"]=>
@@ -90,16 +90,16 @@ array(16) {
9090
int(0)
9191
["f"]=>
9292
float(0)
93+
["invert"]=>
94+
int(0)
95+
["days"]=>
96+
bool(false)
9397
["weekday"]=>
9498
int(0)
9599
["weekday_behavior"]=>
96100
int(0)
97101
["first_last_day_of"]=>
98102
int(0)
99-
["invert"]=>
100-
int(0)
101-
["days"]=>
102-
bool(false)
103103
["special_type"]=>
104104
int(0)
105105
["special_amount"]=>
@@ -108,4 +108,8 @@ array(16) {
108108
int(0)
109109
["have_special_relative"]=>
110110
int(0)
111+
["civil_or_wall"]=>
112+
int(2)
113+
["from_string"]=>
114+
bool(false)
111115
}

ext/date/tests/DateInterval_serialize-002.phpt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ object(DateInterval)#3 (10) {
5959
int(0)
6060
["days"]=>
6161
int(15820)
62-
["have_special_relative"]=>
63-
int(0)
62+
["from_string"]=>
63+
bool(false)
6464
}
6565

6666

6767
Serialised object:
68-
string(340) "O:12:"DateInterval":16:{s:1:"y";i:43;s:1:"m";i:3;s:1:"d";i:24;s:1:"h";i:1;s:1:"i";i:12;s:1:"s";i:27;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:15820;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}"
68+
string(388) "O:12:"DateInterval":18:{s:1:"y";i:43;s:1:"m";i:3;s:1:"d";i:24;s:1:"h";i:1;s:1:"i";i:12;s:1:"s";i:27;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:15820;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:1;s:11:"from_string";b:0;}"
6969

7070

7171
Unserialised object:
@@ -88,13 +88,13 @@ object(DateInterval)#4 (10) {
8888
int(0)
8989
["days"]=>
9090
int(15820)
91-
["have_special_relative"]=>
92-
int(0)
91+
["from_string"]=>
92+
bool(false)
9393
}
9494

9595

9696
Calling __serialize manually:
97-
array(16) {
97+
array(%d) {
9898
["y"]=>
9999
int(43)
100100
["m"]=>
@@ -109,16 +109,16 @@ array(16) {
109109
int(27)
110110
["f"]=>
111111
float(0)
112+
["invert"]=>
113+
int(0)
114+
["days"]=>
115+
int(15820)
112116
["weekday"]=>
113117
int(0)
114118
["weekday_behavior"]=>
115119
int(0)
116120
["first_last_day_of"]=>
117121
int(0)
118-
["invert"]=>
119-
int(0)
120-
["days"]=>
121-
int(15820)
122122
["special_type"]=>
123123
int(0)
124124
["special_amount"]=>
@@ -127,6 +127,10 @@ array(16) {
127127
int(0)
128128
["have_special_relative"]=>
129129
int(0)
130+
["civil_or_wall"]=>
131+
int(1)
132+
["from_string"]=>
133+
bool(false)
130134
}
131135

132136

@@ -150,6 +154,6 @@ object(DateInterval)#5 (10) {
150154
int(0)
151155
["days"]=>
152156
int(15820)
153-
["have_special_relative"]=>
154-
int(0)
157+
["from_string"]=>
158+
bool(false)
155159
}

ext/date/tests/DateInterval_serialize-003.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ object(DateInterval)#1 (10) {
3636
int(0)
3737
["days"]=>
3838
bool(false)
39-
["have_special_relative"]=>
40-
int(1)
39+
["from_string"]=>
40+
bool(false)
4141
}
4242

4343

ext/date/tests/DatePeriod_set_state.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ object(DatePeriod)#%d (6) {
5353
int(0)
5454
["days"]=>
5555
bool(false)
56-
["have_special_relative"]=>
57-
int(0)
56+
["from_string"]=>
57+
bool(false)
5858
}
5959
["recurrences"]=>
6060
int(25)

ext/date/tests/bug45682.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ object(DateInterval)#%d (%d) {
3232
int(0)
3333
["days"]=>
3434
int(3)
35-
["have_special_relative"]=>
36-
int(0)
35+
["from_string"]=>
36+
bool(false)
3737
}

ext/date/tests/bug48678.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DateInterval Object
1919
[f] => 0
2020
[invert] => 0
2121
[days] =>
22-
[have_special_relative] => 0
22+
[from_string] =>
2323
)
2424
DateInterval Object
2525
(
@@ -32,5 +32,5 @@ DateInterval Object
3232
[f] => 0
3333
[invert] => 0
3434
[days] =>
35-
[have_special_relative] => 0
35+
[from_string] =>
3636
)

ext/date/tests/bug49081.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ DateInterval Object
2020
[f] => 0
2121
[invert] => 0
2222
[days] => 30
23-
[have_special_relative] => 0
23+
[from_string] =>
2424
)

ext/date/tests/bug49778.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ object(DateInterval)#%d (%d) {
2727
int(0)
2828
["days"]=>
2929
bool(false)
30-
["have_special_relative"]=>
31-
int(0)
30+
["from_string"]=>
31+
bool(false)
3232
}
3333
7
3434
(unknown)

ext/date/tests/bug52113.phpt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ object(DateInterval)#%d (%d) {
5252
int(0)
5353
["days"]=>
5454
int(0)
55-
["have_special_relative"]=>
56-
int(0)
55+
["from_string"]=>
56+
bool(false)
5757
}
58-
string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}"
59-
\DateInterval::__set_state(array(
58+
string(380) "O:12:"DateInterval":18:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";i:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;s:13:"civil_or_wall";i:1;s:11:"from_string";b:0;}"
59+
DateInterval::__set_state(array(
6060
'y' => 0,
6161
'm' => 0,
6262
'd' => 0,
@@ -66,7 +66,7 @@ string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h"
6666
'f' => 0.0,
6767
'invert' => 0,
6868
'days' => 0,
69-
'have_special_relative' => 0,
69+
'from_string' => false,
7070
))object(DateInterval)#%d (%d) {
7171
["y"]=>
7272
int(0)
@@ -86,8 +86,8 @@ string(332) "O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h"
8686
int(0)
8787
["days"]=>
8888
int(0)
89-
["have_special_relative"]=>
90-
int(0)
89+
["from_string"]=>
90+
bool(false)
9191
}
9292
object(DatePeriod)#%d (6) {
9393
["start"]=>
@@ -123,8 +123,8 @@ object(DatePeriod)#%d (6) {
123123
int(0)
124124
["days"]=>
125125
int(0)
126-
["have_special_relative"]=>
127-
int(0)
126+
["from_string"]=>
127+
bool(false)
128128
}
129129
["recurrences"]=>
130130
int(3)
@@ -150,8 +150,8 @@ object(DateInterval)#%d (%d) {
150150
int(1)
151151
["days"]=>
152152
int(2400)
153-
["have_special_relative"]=>
154-
int(0)
153+
["from_string"]=>
154+
bool(false)
155155
}
156156
object(DatePeriod)#%d (6) {
157157
["start"]=>
@@ -187,8 +187,8 @@ object(DatePeriod)#%d (6) {
187187
int(0)
188188
["days"]=>
189189
int(0)
190-
["have_special_relative"]=>
191-
int(0)
190+
["from_string"]=>
191+
bool(false)
192192
}
193193
["recurrences"]=>
194194
int(3)

ext/date/tests/bug52738.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ di Object
3131
[f] => 0
3232
[invert] => 0
3333
[days] =>
34-
[have_special_relative] => 0
34+
[from_string] =>
3535
)

ext/date/tests/bug52808.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ object(DateInterval)#%d (%d) {
4444
int(1)
4545
["days"]=>
4646
int(437)
47-
["have_special_relative"]=>
48-
int(0)
47+
["from_string"]=>
48+
bool(false)
4949
}
5050
object(DateInterval)#%d (%d) {
5151
["y"]=>
@@ -66,8 +66,8 @@ object(DateInterval)#%d (%d) {
6666
int(0)
6767
["days"]=>
6868
int(294)
69-
["have_special_relative"]=>
70-
int(0)
69+
["from_string"]=>
70+
bool(false)
7171
}
7272
object(DateInterval)#%d (%d) {
7373
["y"]=>
@@ -88,8 +88,8 @@ object(DateInterval)#%d (%d) {
8888
int(0)
8989
["days"]=>
9090
int(294)
91-
["have_special_relative"]=>
92-
int(0)
91+
["from_string"]=>
92+
bool(false)
9393
}
9494
Failed to parse interval (2007-05-11T15:30:00Z/)
9595
Failed to parse interval (2007-05-11T15:30:00Z)

ext/date/tests/bug53437.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ object(DatePeriod)#%d (6) {
6969
int(0)
7070
["days"]=>
7171
bool(false)
72-
["have_special_relative"]=>
73-
int(0)
72+
["from_string"]=>
73+
bool(false)
7474
}
7575
["recurrences"]=>
7676
int(3)
@@ -118,8 +118,8 @@ object(DatePeriod)#%d (6) {
118118
int(0)
119119
["days"]=>
120120
bool(false)
121-
["have_special_relative"]=>
122-
int(0)
121+
["from_string"]=>
122+
bool(false)
123123
}
124124
["recurrences"]=>
125125
int(3)

0 commit comments

Comments
 (0)