PHP :: Bug #52430 :: date_parse parse 24:xx:xx as valid time
| Bug #52430 | date_parse parse 24:xx:xx as valid time | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2010-07-24 21:20 UTC | Modified: | 2010-08-30 18:40 UTC |
|
||||||||||
| From: | pulzarraider at gmail dot com | Assigned: | derick (profile) | |||||||||||
| Status: | Closed | Package: | Date/time related | |||||||||||
| PHP Version: | 5.3.3 | OS: | Win 7 | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2010-07-24 21:20 UTC] pulzarraider at gmail dot com
Description:
------------
In the 24-hour time notation, the day begins at midnight, 00:00, and the last minute of the day begins at 23:59.
Date_parse function returns no warning and no error when any time starting with hour "24" is used as parameter. But some error is expected, because 2010-1-1 24:59:59 is NOT valid date.
This can cause serious errors in scripts that use date_parse for validating dateTime strings.
Test script:
---------------
<?php
date_parse('2010-1-1 24:00:00');
//This is invalid date, but date_parse returns no error and warning
//Expected: error "Unexpected character"
//date_parse('2010-1-1 24:59:59');
//This is also invalid date, but date_parse returns no error and warning
//Expected: error "Unexpected character"
?>
Expected result:
----------------
Array (
[year] => 2010
[month] => 1
[day] => 1
[hour] => 0
[minute] => 0
[second] => 0
[fraction] => 0
[warning_count] => 0
[warnings] => Array ( )
[error_count] => 1
[errors] => Array ([9]=>'Unexpected character')
[is_localtime] =>false
)
Actual result:
--------------
Array (
[year] => 2010
[month] => 1
[day] => 1
[hour] => 24 <===== wrong
[minute] => 0
[second] => 0
[fraction] => 0
[warning_count] => 0
[warnings] => Array ( )
[error_count] => 0 <===== wrong
[errors] => Array ( ) <===== wrong
[is_localtime] =>false
)
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2010-07-26 08:00 UTC] dtajchreber@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: derick
[2010-07-26 08:00 UTC] dtajchreber@php.net
[2010-07-26 11:54 UTC] derick@php.net
date_parse (and friends) are not made to validate. It will also happily accept "2010-02-31" as a date. Since PHP 5.3.x, date_parse() however adds a warning if a date is invalid; I should add that for time as well: derick@kossu:/tmp$ php bug52430.php array(12) { ["year"]=> int(2010) ["month"]=> int(2) ["day"]=> int(31) ["hour"]=> int(24) ["minute"]=> int(52) ["second"]=> int(59) ["warning_count"]=> int(1) ["warnings"]=> array(1) { [20]=> string(27) "The parsed date was invalid" }[2010-08-30 18:40 UTC] derick@php.net
-Status: Verified +Status: Closed
[2010-08-30 18:40 UTC] derick@php.net