Doc #67921 [Opn->Csd]: createFromFormat allows overflow for 'H' and 'G' so 25-99 rolls to next day
[email protected] Fri, 13 May 2022 14:27:57 +0000
| Newsgroups | php.doc.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=67921&edit=1 ID: 67921 Updated by: [email protected] Reported by: crazytonyi at gmail dot com Summary: createFromFormat allows overflow for 'H' and 'G' so 25-99 rolls to next day -Status: Open +Status: Closed Type: Documentation Problem Package: Date/time related PHP Version: 5.5.16 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2020-08-03 22:40:35] thomas at landauer dot at I just opened a related issue: https://bugs.php.net/bug.php?id=79926 ------------------------------------------------------------------------ [2014-08-28 16:28:11] [email protected] 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. ------------------------------------------------------------------------ [2014-08-28 07:32:34] 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); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67921&edit=1