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: Closed Package: Date/time related
PHP Version: 5.5.16 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
43 + 20 = ?
Subscribe to this entry?

 
 [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
 [2022-05-13 14:27 UTC] git@php.net
Automatic comment on behalf of derickr
Revision: https://github.com/php/doc-en/commit/5267e13731a496c2a2544433ee02a5314e1391d6
Log: Fixed bug #67921: createFromFormat allows overflow for 'H' and 'G' so 25-99 rolls to next day
 [2022-05-13 14:27 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC