reference/datetime/dateinterval/construct.xml
71692b6f4cace8dca72a18ccd80d4cd7305e5d4e
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="dateinterval.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>DateInterval::__construct</refname>
...
...
@@ -9,7 +8,7 @@
9
8

10
9
<refsect1 role="description">
11
10
&reftitle.description;
12
-
<constructorsynopsis role="oop">
11
+
<constructorsynopsis role="DateInterval">
13
12
<modifier>public</modifier> <methodname>DateInterval::__construct</methodname>
14
13
<methodparam><type>string</type><parameter>duration</parameter></methodparam>
15
14
</constructorsynopsis>
...
...
@@ -110,8 +109,7 @@
110
109
roll-over-point (e.g. <literal>25</literal> hours is invalid).
111
110
</para>
112
111
<para>
113
-
These formats are based on the <link
114
-
xlink:href="&url.iso-8601.duration;">ISO 8601 duration
112
+
These formats are based on the <link xlink:href="&url.iso-8601.duration;">ISO 8601 duration
115
113
specification</link>.
116
114
</para>
117
115
</listitem>
...
...
@@ -123,8 +121,9 @@
123
121
<refsect1 role="errors">
124
122
&reftitle.errors;
125
123
<para>
126
-
Throws an <classname>Exception</classname> when the <parameter>duration</parameter>
127
-
cannot be parsed as an interval.
124
+
Throws an <classname>DateMalformedIntervalStringException</classname> when
125
+
the <parameter>duration</parameter> cannot be parsed as an interval. Prior
126
+
to PHP 8.3, this was <exceptionname>Exception</exceptionname>.
128
127
</para>
129
128
</refsect1>
130
129

...
...
@@ -140,6 +139,22 @@
140
139
</thead>
141
140
<tbody>
142
141
<row>
142
+
<entry>8.3.0</entry>
143
+
<entry>
144
+
Now throws
145
+
<exceptionname>DateMalformedIntervalStringException</exceptionname>
146
+
instead of <exceptionname>Exception</exceptionname>.
147
+
</entry>
148
+
</row>
149
+
<row>
150
+
<entry>8.2.0</entry>
151
+
<entry>
152
+
Only the <literal>y</literal> to <literal>f</literal>,
153
+
<literal>invert</literal>, and <literal>days</literal> will be visible,
154
+
including a new <literal>from_string</literal> boolean property.
155
+
</entry>
156
+
</row>
157
+
<row>
143
158
<entry>8.0.0</entry>
144
159
<entry>
145
160
<literal>W</literal> can be combined with <literal>D</literal>.
...
...
@@ -154,6 +169,32 @@
154
169
&reftitle.examples;
155
170
<para>
156
171
<example>
172
+
<title>Constructing and using <classname>DateInterval</classname> objects</title>
173
+
<programlisting role="php">
174
+
<![CDATA[
175
+
<?php
176
+
// Create a specific date
177
+
$someDate = \DateTime::createFromFormat("Y-m-d H:i", "2022-08-25 14:18");
178
+

179
+
// Create interval
180
+
$interval = new \DateInterval("P7D");
181
+

182
+
// Add interval
183
+
$someDate->add($interval);
184
+

185
+
// Convert interval to string
186
+
echo $interval->format("%d");
187
+
]]>
188
+
</programlisting>
189
+
&example.outputs;
190
+
<screen role="php">
191
+
7
192
+
</screen>
193
+
</example>
194
+
</para>
195
+

196
+
<para>
197
+
<example>
157
198
<title><classname>DateInterval</classname> example</title>
158
199
<programlisting role="php">
159
200
<![CDATA[
...
...
@@ -165,6 +206,33 @@ var_dump($interval);
165
206
?>
166
207
]]>
167
208
</programlisting>
209
+
&example.outputs.82;
210
+
<screen role="php">
211
+
<![CDATA[
212
+
object(DateInterval)#1 (10) {
213
+
["y"]=>
214
+
int(0)
215
+
["m"]=>
216
+
int(0)
217
+
["d"]=>
218
+
int(9)
219
+
["h"]=>
220
+
int(0)
221
+
["i"]=>
222
+
int(0)
223
+
["s"]=>
224
+
int(0)
225
+
["f"]=>
226
+
float(0)
227
+
["invert"]=>
228
+
int(0)
229
+
["days"]=>
230
+
bool(false)
231
+
["from_string"]=>
232
+
bool(false)
233
+
}
234
+
]]>
235
+
</screen>
168
236
&example.outputs.8;
169
237
<screen role="php">
170
238
<![CDATA[
...
...
@@ -260,7 +328,6 @@ object(DateInterval)#1 (16) {
260
328
</refsect1>
261
329

262
330
</refentry>
263
-

264
331
<!-- Keep this comment at the end of the file
265
332
Local variables:
266
333
mode: sgml
267
334