php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67921 createFromFormat allows overflow for 'H' and 'G' so 25-99 rolls to next day
Submitted: 2014-08-28 07:32 UTC Modified: 2014-08-28 16:28 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: crazytonyi at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 5.5.16 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: crazytonyi at gmail dot com
New email:
PHP Version: OS:

 

 [2014-08-28 07:32 UTC] crazytonyi at gmail dot com
Description:
------------
When a value between 24 and 99 is in date/time string evaluated by DateTime:createFromFormat , it handles as valid and resulting object is Date + hours % 24 . So 36:00 is treated as date + 1 day 12:00

Expected Result:  Evaluates to false.

If this is by design, it should be very clearly documented. Since 100:00 returns false, this does not seem intentional.

Test script:
---------------
$time="30:29"; 
$date =  DateTime::createFromFormat("H:m", $time);
echo $date->format(DateTime::W3C);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-28 16:28 UTC] requinix@php.net
-Type: Bug +Type: Documentation Problem
 [2014-08-28 16:28 UTC] requinix@php.net
This is standard behavior for date functions: when the input matches the format constraints (eg, 'H' is a two-digit number) then numbers above and below the valid range will over-/underflow.
"100:00" isn't valid for "H:m" because the hour cannot be three digits.
 [2020-08-03 22:40 UTC] thomas at landauer dot at
I just opened a related issue: https://bugs.php.net/bug.php?id=79926
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Sep 29 07:01:23 2020 UTC