|
27 | 27 | <term><parameter>format</parameter></term>
|
28 | 28 | <listitem>
|
29 | 29 | <para>
|
30 |
| - Format accepted by <function>DateTime::createFromFormat</function>. |
| 30 | + Format accepted by <function>DateTimeImmutable::createFromFormat</function>. |
31 | 31 | </para>
|
32 | 32 | </listitem>
|
33 | 33 | </varlistentry>
|
|
49 | 49 | <para>
|
50 | 50 | Returns associative array with detailed info about given date/time.
|
51 | 51 | </para>
|
| 52 | + <para> |
| 53 | + The returned array has keys for <literal>year</literal>, |
| 54 | + <literal>month</literal>, <literal>day</literal>, <literal>hour</literal>, |
| 55 | + <literal>minute</literal>, <literal>second</literal>, |
| 56 | + <literal>fraction</literal>, and <literal>is_localtime</literal>. |
| 57 | + </para> |
| 58 | + <para> |
| 59 | + If <literal>is_localtime</literal> is present then |
| 60 | + <literal>zone_type</literal> indicates the type of timezone. For type |
| 61 | + <literal>1</literal> (UTC offset) the <literal>zone</literal>, |
| 62 | + <literal>is_dst</literal> fields are added; for type <literal>2</literal> |
| 63 | + (abbreviation) the fields <literal>tz_abbr</literal>, |
| 64 | + <literal>is_dst</literal> are added; and for type <literal>3</literal> |
| 65 | + (timezone identifier) the <literal>tz_abbr</literal>, |
| 66 | + <literal>tz_id</literal> are added. |
| 67 | + </para> |
| 68 | + <para> |
| 69 | + The array includes <literal>warning_count</literal> and |
| 70 | + <literal>warnings</literal> fields. The first one indicate how many |
| 71 | + warnings there were. |
| 72 | + The keys of elements <literal>warnings</literal> array indicate the |
| 73 | + position in the given <parameter>datetime</parameter> where the warning |
| 74 | + occurred, with the string value describing the warning itself. An example |
| 75 | + below shows such a warning. |
| 76 | + </para> |
| 77 | + <para> |
| 78 | + The array also contains <literal>error_count</literal> and |
| 79 | + <literal>errors</literal> fields. The first one indicate how many errors |
| 80 | + were found. |
| 81 | + The keys of elements <literal>errors</literal> array indicate the |
| 82 | + position in the given <parameter>datetime</parameter> where the error |
| 83 | + occurred, with the string value describing the error itself. An example |
| 84 | + below shows such an error. |
| 85 | + </para> |
| 86 | + <warning> |
| 87 | + <para> |
| 88 | + The number of array elements in the <literal>warnings</literal> and |
| 89 | + <literal>errors</literal> arrays might be less than |
| 90 | + <literal>warning_count</literal> or <literal>error_count</literal> if they |
| 91 | + occurred at the same position. |
| 92 | + </para> |
| 93 | + </warning> |
52 | 94 | </refsect1>
|
53 | 95 |
|
54 | 96 | <refsect1 role="changelog">
|
@@ -115,16 +157,70 @@ Array
|
115 | 157 | [zone] => 3600
|
116 | 158 | [is_dst] =>
|
117 | 159 | )
|
| 160 | +]]> |
| 161 | + </screen> |
| 162 | + </example> |
| 163 | + </para> |
| 164 | + |
| 165 | + <para> |
| 166 | + <example> |
| 167 | + <title><function>date_parse_from_format</function> with warnings example</title> |
| 168 | + <programlisting role="php"> |
| 169 | +<![CDATA[ |
| 170 | +<?php |
| 171 | +$date = "26 August 2022 22:30 pm"; |
| 172 | +$parsed = date_parse_from_format("j F Y G:i a", $date); |
| 173 | +
|
| 174 | +echo "Warnings count: ", $parsed['warning_count'], "\n"; |
| 175 | +foreach ($parsed['warnings'] as $position => $message) { |
| 176 | + echo "\tOn position {$position}: {$message}\n"; |
| 177 | +} |
| 178 | +?> |
| 179 | +]]> |
| 180 | + </programlisting> |
| 181 | + &example.outputs; |
| 182 | + <screen> |
| 183 | +<![CDATA[ |
| 184 | +Warnings count: 1 |
| 185 | + On position 23: The parsed time was invalid |
| 186 | +]]> |
| 187 | + </screen> |
| 188 | + </example> |
| 189 | + </para> |
| 190 | + |
| 191 | + <para> |
| 192 | + <example> |
| 193 | + <title><function>date_parse_from_format</function> with errors example</title> |
| 194 | + <programlisting role="php"> |
| 195 | +<![CDATA[ |
| 196 | +<?php |
| 197 | +$date = "26 August 2022 CEST"; |
| 198 | +$parsed = date_parse_from_format("j F Y H:i", $date); |
| 199 | +
|
| 200 | +echo "Errors count: ", $parsed['error_count'], "\n"; |
| 201 | +foreach ($parsed['errors'] as $position => $message) { |
| 202 | + echo "\tOn position {$position}: {$message}\n"; |
| 203 | +} |
| 204 | +?> |
| 205 | +]]> |
| 206 | + </programlisting> |
| 207 | + &example.outputs; |
| 208 | + <screen> |
| 209 | +<![CDATA[ |
| 210 | +Errors count: 3 |
| 211 | + On position 15: A two digit hour could not be found |
| 212 | + On position 19: Data missing |
118 | 213 | ]]>
|
119 | 214 | </screen>
|
120 | 215 | </example>
|
121 | 216 | </para>
|
122 | 217 | </refsect1>
|
| 218 | + |
123 | 219 | <refsect1 role="seealso">
|
124 | 220 | &reftitle.seealso;
|
125 | 221 | <para>
|
126 | 222 | <simplelist>
|
127 |
| - <member><function>DateTime::createFromFormat</function></member> |
| 223 | + <member><function>DateTimeImmutable::createFromFormat</function></member> |
128 | 224 | <member><function>checkdate</function></member>
|
129 | 225 | </simplelist>
|
130 | 226 | </para>
|
|
0 commit comments