-
Notifications
You must be signed in to change notification settings - Fork 788
/
Copy pathconstruct.xml
331 lines (316 loc) · 9.38 KB
/
construct.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="dateperiod.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>DatePeriod::__construct</refname>
<refpurpose>Creates a new DatePeriod object</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<constructorsynopsis role="DatePeriod">
<modifier>public</modifier> <methodname>DatePeriod::__construct</methodname>
<methodparam><type>DateTimeInterface</type><parameter>start</parameter></methodparam>
<methodparam><type>DateInterval</type><parameter>interval</parameter></methodparam>
<methodparam><type>int</type><parameter>recurrences</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>0</initializer></methodparam>
</constructorsynopsis>
<constructorsynopsis role="DatePeriod">
<modifier>public</modifier> <methodname>DatePeriod::__construct</methodname>
<methodparam><type>DateTimeInterface</type><parameter>start</parameter></methodparam>
<methodparam><type>DateInterval</type><parameter>interval</parameter></methodparam>
<methodparam><type>DateTimeInterface</type><parameter>end</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>0</initializer></methodparam>
</constructorsynopsis>
<warning>
<constructorsynopsis role="DatePeriod">
<modifier>public</modifier> <methodname>DatePeriod::__construct</methodname>
<methodparam><type>string</type><parameter>isostr</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>0</initializer></methodparam>
</constructorsynopsis>
<simpara>
This variant of the constructor has been deprecated, use
<methodname>DatePeriod::createFromISO8601String</methodname> instead.
</simpara>
</warning>
<para>
Creates a new DatePeriod object.
</para>
<para>
<classname>DatePeriod</classname> objects can be used as an iterator to
generate a number of <classname>DateTimeImmutable</classname> or
<classname>DateTime</classname> object from a <parameter>start</parameter>
date, a <parameter>interval</parameter>, and an <parameter>end</parameter>
date or the number of <parameter>recurrences</parameter>.
</para>
<para>
The class of returned objects is equivalent to the
<classname>DateTimeImmutable</classname> or <classname>DateTime</classname>
ancestor class of the <parameter>start</parameter> object.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>start</parameter></term>
<listitem>
<para>
The start date of the period. Included by default in the result set.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>interval</parameter></term>
<listitem>
<para>
The interval between recurrences within the period.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>recurrences</parameter></term>
<listitem>
<para>
The number of recurrences. The number of returned results is
one higher than this, as the start date is included in the result set
by default. Must be greater than <literal>0</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>end</parameter></term>
<listitem>
<para>
The end date of the period. Excluded by default from the result set.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>isostr</parameter></term>
<listitem>
<para>
A subset of the <link
xlink:href="&url.iso-8601.repeating_intervals;">ISO 8601 repeating
interval specification</link>.
</para>
<para>
Examples of some ISO 8601 interval specification features that PHP does
not support are:
</para>
<orderedlist>
<listitem>
<simpara>
zero occurrences (<literal>R0/</literal>)
</simpara>
</listitem>
<listitem>
<simpara>
time offsets other than UTC (<literal>Z</literal>), such as <literal>+02:00</literal>.
</simpara>
</listitem>
</orderedlist>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
A bit field which can be used to control certain behaviour with start-
and end- dates.
</para>
<para>
With <constant>DatePeriod::EXCLUDE_START_DATE</constant> you
exclude the start date from the set of recurring dates within the
period.
</para>
<para>
With <constant>DatePeriod::INCLUDE_END_DATE</constant> you
include the end date in the set of recurring dates within the
period.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws an <classname>DateMalformedPeriodStringException</classname> when
the <parameter>isostr</parameter> cannot be parsed as a valid ISO 8601
period. Prior to PHP 8.3, this was
<exceptionname>Exception</exceptionname>.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
Now throws
<exceptionname>DateMalformedPeriodStringException</exceptionname>
instead of <exceptionname>Exception</exceptionname>.
</entry>
</row>
<row>
<entry>8.2.0</entry>
<entry>
The <constant>DatePeriod::INCLUDE_END_DATE</constant> constant has been added.
</entry>
</row>
<row>
<entry>7.2.19, 7.3.6, 7.4.0</entry>
<entry>
<parameter>recurrences</parameter> must be greater than <literal>0</literal> now.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>DatePeriod example</title>
<programlisting role="php">
<![CDATA[
<?php
$start = new DateTime('2012-07-01');
$interval = new DateInterval('P7D');
$end = new DateTime('2012-07-31');
$recurrences = 4;
$iso = 'R4/2012-07-01T00:00:00Z/P7D';
// All of these periods are equivalent.
$period = new DatePeriod($start, $interval, $recurrences);
$period = new DatePeriod($start, $interval, $end);
$period = new DatePeriod($iso);
// By iterating over the DatePeriod object, all of the
// recurring dates within that period are printed.
foreach ($period as $date) {
echo $date->format('Y-m-d')."\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
2012-07-01
2012-07-08
2012-07-15
2012-07-22
2012-07-29
]]>
</screen>
</example>
</para>
<para>
<example>
<title>DatePeriod example with <constant>DatePeriod::EXCLUDE_START_DATE</constant></title>
<programlisting role="php">
<![CDATA[
<?php
$start = new DateTime('2012-07-01');
$interval = new DateInterval('P7D');
$end = new DateTime('2012-07-31');
$period = new DatePeriod($start, $interval, $end,
DatePeriod::EXCLUDE_START_DATE);
// By iterating over the DatePeriod object, all of the
// recurring dates within that period are printed.
// Note that, in this case, 2012-07-01 is not printed.
foreach ($period as $date) {
echo $date->format('Y-m-d')."\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
2012-07-08
2012-07-15
2012-07-22
2012-07-29
]]>
</screen>
</example>
</para>
<para>
<example>
<title>DatePeriod example showing all last Thursdays in a year</title>
<programlisting role="php">
<![CDATA[
<?php
$begin = new DateTime('2021-12-31');
$end = new DateTime('2022-12-31 23:59:59');
$interval = DateInterval::createFromDateString('last thursday of next month');
$period = new DatePeriod($begin, $interval, $end, DatePeriod::EXCLUDE_START_DATE);
foreach ($period as $dt) {
echo $dt->format('l Y-m-d'), "\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Thursday 2022-01-27
Thursday 2022-02-24
Thursday 2022-03-31
Thursday 2022-04-28
Thursday 2022-05-26
Thursday 2022-06-30
Thursday 2022-07-28
Thursday 2022-08-25
Thursday 2022-09-29
Thursday 2022-10-27
Thursday 2022-11-24
Thursday 2022-12-29
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<simpara>
Unbound numbers of repetitions as specified by ISO 8601 section 4.5
"Recurring time interval" are not supported, i.e. neither passing
<literal>"R/..."</literal> as <parameter>isostr</parameter> nor passing
&null; as <parameter>end</parameter> would work.
</simpara>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->