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: -
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: Open Package: Date/time related
PHP Version: 5.6.17 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hamid dot a85 at gmail dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Sep 29 08:01:24 2020 UTC