Skip to content

Commit

Permalink
Fixed bug #77701: DateTime::createFromFormat does not set default parts
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Jun 2, 2022
1 parent b90e4a6 commit e5373bc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions reference/datetime/datetimeimmutable/createfromformat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
difference to UTC with colon between hours and minutes, or timezone
abbreviation</entry>
<entry>Examples: <literal>UTC</literal>, <literal>GMT</literal>,
<literal>Atlantic/Azores</literal> or
<literal>Atlantic/Azores</literal> or
<literal>+0200</literal> or <literal>+02:00</literal> or
<literal>EST</literal>, <literal>MDT</literal>
</entry>
Expand Down Expand Up @@ -303,24 +303,28 @@
parsing to fail and an error message is appended to the returned
structure. You can query error messages with
<methodname>DateTimeImmutable::getLastErrors</methodname>.
</para>
</para>
<para>
To include literal characters in <parameter>format</parameter>, you have
to escape them with a backslash (<literal>\</literal>).
</para>
<para>
If <parameter>format</parameter> does not contain the character
<literal>!</literal> then portions of the generated time which are not
<literal>!</literal> then portions of the generated date/time which are not
specified in <parameter>format</parameter> will be set to the current
system time.
</para>
<para>
If <parameter>format</parameter> contains the
character <literal>!</literal>, then portions of the generated
time not provided in <parameter>format</parameter>, as well as
date/time not provided in <parameter>format</parameter>, as well as
values to the left-hand side of the <literal>!</literal>, will
be set to corresponding values from the Unix epoch.
</para>
<para>
If any time character is parsed, then all other time-related fields are
set to "0", unless also parsed.
</para>
<para>
The Unix epoch is 1970-01-01 00:00:00 UTC.
</para>
Expand Down Expand Up @@ -428,17 +432,22 @@ echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";
$format = '!d';
$date = DateTimeImmutable::createFromFormat($format, '15');
echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";
$format = 'i';
$date = DateTimeImmutable::createFromFormat($format, '15');
echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Current time: 2010-04-23 10:29:35
Format: Y-m-d; 2009-02-15 10:29:35
Current time: 2022-06-02 15:50:46
Format: Y-m-d; 2009-02-15 15:50:46
Format: Y-m-d H:i:s; 2009-02-15 15:16:17
Format: Y-m-!d H:i:s; 1970-01-15 15:16:17
Format: !d; 1970-01-15 00:00:00
Format: i; 2022-06-02 00:15:00
]]>
</screen>
</example>
Expand Down

0 comments on commit e5373bc

Please sign in to comment.