php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71407 Accept one digit minutes and seconds in date_create_from_format() function
Submitted: 2016-01-18 15:07 UTC Modified: 2022-06-05 13:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: hamid dot a85 at gmail dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.6.17 OS:
Private report: No CVE-ID: None
 [2016-01-18 15:07 UTC] 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,
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-23 13:35 UTC] cmb@php.net
For reference: <https://3v4l.org/LURlS>.
 [2022-06-05 13:42 UTC] derick@php.net
-Status: Open +Status: Wont fix
 [2022-06-05 13:42 UTC] derick@php.net
I am marking this as "won't fix". If you are still interested in having this feature, please file a new issue at https://github.com/php/php-src/issues/ with a well defined and explained use case.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC