|
31 | 31 | <para>
|
32 | 32 | Creates a new DatePeriod object.
|
33 | 33 | </para>
|
| 34 | + <para> |
| 35 | + <classname>DatePeriod</classname> objects can be used as an iterator to |
| 36 | + generate a number of <classname>DateTimeImmutable</classname> or |
| 37 | + <classname>DateTime</classname> object from a <parameter>start</parameter> |
| 38 | + date, a <parameter>interval</parameter>, and an <parameter>end</parameter> |
| 39 | + date or the number of <parameter>recurrences</parameter>. |
| 40 | + </para> |
| 41 | + <para> |
| 42 | + The class of returned objects is equivalent to the |
| 43 | + <classname>DateTimeImmutable</classname> or <classname>DateTime</classname> |
| 44 | + ancester class of the <parameter>start</parameter> object. |
| 45 | + </para> |
34 | 46 | </refsect1>
|
35 | 47 |
|
36 | 48 | <refsect1 role="parameters">
|
|
41 | 53 | <term><parameter>start</parameter></term>
|
42 | 54 | <listitem>
|
43 | 55 | <para>
|
44 |
| - The start date of the period. |
| 56 | + The start date of the period. Included by default in the result set. |
45 | 57 | </para>
|
46 | 58 | </listitem>
|
47 | 59 | </varlistentry>
|
|
57 | 69 | <term><parameter>recurrences</parameter></term>
|
58 | 70 | <listitem>
|
59 | 71 | <para>
|
60 |
| - The number of recurrences. Must be greater than <literal>0</literal>. |
| 72 | + The number of recurrences. The number of returned results is |
| 73 | + one higher than this, as the start date is included in the result set |
| 74 | + by default. Must be greater than <literal>0</literal>. |
61 | 75 | </para>
|
62 | 76 | </listitem>
|
63 | 77 | </varlistentry>
|
64 | 78 | <varlistentry>
|
65 | 79 | <term><parameter>end</parameter></term>
|
66 | 80 | <listitem>
|
67 | 81 | <para>
|
68 |
| - The end date of the period. |
| 82 | + The end date of the period. Excluded by default in the result set. |
69 | 83 | </para>
|
70 | 84 | </listitem>
|
71 | 85 | </varlistentry>
|
|
83 | 97 | <term><parameter>options</parameter></term>
|
84 | 98 | <listitem>
|
85 | 99 | <para>
|
86 |
| - Can be set to <constant>DatePeriod::EXCLUDE_START_DATE</constant> to |
| 100 | + A bit field which can be used to control certain behaviour with start- |
| 101 | + and end- dates. |
| 102 | + </para> |
| 103 | + <para> |
| 104 | + With <constant>DatePeriod::EXCLUDE_START_DATE</constant> you |
87 | 105 | exclude the start date from the set of recurring dates within the
|
88 | 106 | period.
|
89 | 107 | </para>
|
| 108 | + <para> |
| 109 | + With <constant>DatePeriod::INCLUDE_END_DATE</constant> you |
| 110 | + include the end date from the set of recurring dates within the |
| 111 | + period. |
| 112 | + </para> |
90 | 113 | </listitem>
|
91 | 114 | </varlistentry>
|
92 | 115 | </variablelist>
|
|
105 | 128 | </row>
|
106 | 129 | </thead>
|
107 | 130 | <tbody>
|
| 131 | + <row> |
| 132 | + <entry>8.2.0</entry> |
| 133 | + <entry> |
| 134 | + The <constant>DatePeriod::INCLUDE_END_DATE</constant> constant has been added. |
| 135 | + </entry> |
| 136 | + </row> |
108 | 137 | <row>
|
109 | 138 | <entry>7.2.19, 7.3.6, 7.4.0</entry>
|
110 | 139 | <entry>
|
@@ -185,6 +214,43 @@ foreach ($period as $date) {
|
185 | 214 | 2012-07-15
|
186 | 215 | 2012-07-22
|
187 | 216 | 2012-07-29
|
| 217 | +]]> |
| 218 | + </screen> |
| 219 | + </example> |
| 220 | + </para> |
| 221 | + <para> |
| 222 | + <example> |
| 223 | + <title>DatePeriod example showing all last Thursdays in a year</title> |
| 224 | + <programlisting role="php"> |
| 225 | +<![CDATA[ |
| 226 | +<?php |
| 227 | +$begin = new DateTime('2021-12-31'); |
| 228 | +$end = new DateTime('2022-12-31 23:59:59'); |
| 229 | +
|
| 230 | +$interval = DateInterval::createFromDateString('last thursday of next month'); |
| 231 | +$period = new DatePeriod($begin, $interval, $end, DatePeriod::EXCLUDE_START_DATE); |
| 232 | +
|
| 233 | +foreach ($period as $dt) { |
| 234 | + echo $dt->format('l Y-m-d'), "\n"; |
| 235 | +} |
| 236 | +?> |
| 237 | +]]> |
| 238 | + </programlisting> |
| 239 | + &example.outputs; |
| 240 | + <screen> |
| 241 | +<![CDATA[ |
| 242 | +Thursday 2022-01-27 |
| 243 | +Thursday 2022-02-24 |
| 244 | +Thursday 2022-03-31 |
| 245 | +Thursday 2022-04-28 |
| 246 | +Thursday 2022-05-26 |
| 247 | +Thursday 2022-06-30 |
| 248 | +Thursday 2022-07-28 |
| 249 | +Thursday 2022-08-25 |
| 250 | +Thursday 2022-09-29 |
| 251 | +Thursday 2022-10-27 |
| 252 | +Thursday 2022-11-24 |
| 253 | +Thursday 2022-12-29 |
188 | 254 | ]]>
|
189 | 255 | </screen>
|
190 | 256 | </example>
|
|
0 commit comments