From e5373bc7610639edca743a5d190e78e6cf41b42f Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 2 Jun 2022 16:51:53 +0100 Subject: [PATCH] Fixed bug #77701: DateTime::createFromFormat does not set default parts --- .../datetimeimmutable/createfromformat.xml | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/reference/datetime/datetimeimmutable/createfromformat.xml b/reference/datetime/datetimeimmutable/createfromformat.xml index dd7e7eeb98..5875f65cd2 100644 --- a/reference/datetime/datetimeimmutable/createfromformat.xml +++ b/reference/datetime/datetimeimmutable/createfromformat.xml @@ -208,7 +208,7 @@ difference to UTC with colon between hours and minutes, or timezone abbreviation Examples: UTC, GMT, - Atlantic/Azores or + Atlantic/Azores or +0200 or +02:00 or EST, MDT @@ -303,24 +303,28 @@ parsing to fail and an error message is appended to the returned structure. You can query error messages with DateTimeImmutable::getLastErrors. - + To include literal characters in format, you have to escape them with a backslash (\). If format does not contain the character - ! then portions of the generated time which are not + ! then portions of the generated date/time which are not specified in format will be set to the current system time. If format contains the character !, then portions of the generated - time not provided in format, as well as + date/time not provided in format, as well as values to the left-hand side of the !, will be set to corresponding values from the Unix epoch. + + If any time character is parsed, then all other time-related fields are + set to "0", unless also parsed. + The Unix epoch is 1970-01-01 00:00:00 UTC. @@ -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"; ?> ]]> &example.outputs.similar;