Req #71407 [Opn]: Accept one digit minutes and seconds in date_create_from_format() function

From: Date: Thu, 23 Sep 2021 13:35:25 +0000
Subject: Req #71407 [Opn]: Accept one digit minutes and seconds in date_create_from_format() function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236780@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71407&edit=1 ID: 71407 Updated by: cmb@php.net Reported by: hamid dot a85 at gmail dot com Summary: Accept one digit minutes and seconds in date_create_from_format() function Status: Open Type: Feature/Change Request Package: Date/time related PHP Version: 5.6.17 Block user comment: N Private report: N New Comment: For reference: <https://3v4l.org/LURlS>. Previous Comments: ------------------------------------------------------------------------ [2016-01-18 15:07:15] hamid dot a85 at gmail dot com Description: ------------ Currently, there is no way for date_create_from_format() to accept one digit seconds/minutes. But they do accept one digit hours, month, and years: date_create_from_format('Y-m-d H:i:s', '2016-1-2 3:04:05'); will output a DateTime object, but the following code will return false: date_create_from_format('Y-m-d H:i:s', '2016-1-2 3:4:5'); Although backward compatibility may be an issue, I guess it would be nice if one digit seconds and minutes like '4:5' be accepted by date_create_from_format() and date_parse_from_format(). Test script: --------------- var_export(date_create_from_format('Y-m-d H:i:s', '2016-1-2 3:4:5')); var_export(date_parse_from_format('Y-m-d H:i:s', '2016-1-2 3:4:5')); Expected result: ---------------- DateTime::__set_state(array( 'date' => '2016-01-02 03:04:05', 'timezone_type' => 3, 'timezone' => 'Asia/Tehran', )) array ( 'year' => 2016, 'month' => 1, 'day' => 2, 'hour' => 3, 'minute' => 4, 'second' => 5, 'fraction' => false, 'warning_count' => 0, 'warnings' => array ( ), 'error_count' => 0, 'errors' => array ( ), 'is_localtime' => false, ) Actual result: -------------- false array ( 'year' => 2016, 'month' => 1, 'day' => 2, 'hour' => 3, 'minute' => 0, 'second' => 0, 'fraction' => false, 'warning_count' => 0, 'warnings' => array ( ), 'error_count' => 2, 'errors' => array ( 11 => 'A two digit minute could not be found', 13 => 'A two digit second could not be found', ), 'is_localtime' => false, ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71407&edit=1

« previous php.bugs (#236780) next »