Bug #71728 [Opn->Fbk]: date functions leading zeros ingnore
Edit report at https://bugs.php.net/bug.php?id=71728&edit=1
ID: 71728
Updated by: requinix@php.net
Reported by: shadowspawnshadow at gmail dot com
Summary: date functions leading zeros ingnore
-Status: Open
+Status: Feedback
Type: Bug
Package: Date/time related
Operating System: Windows
PHP Version: 5.5.33
Block user comment: N
Private report: N
New Comment:
Is this creating an actual problem for you? Or how about we just change the documentation to say
that leading zeroes are ignored?
Previous Comments:
------------------------------------------------------------------------
[2016-03-07 10:08:13] shadowspawnshadow at gmail dot com
Description:
------------
Date functions/methods like date_parse_from_format(),
date_create_from_format()/DateTime::createFromFormat() ignore leading zeros in format and date
string. So doe not make sense you use, for example, 'm' or 'n', both
'01' and '1' passed without errors or warnings.
Looks relevant to all versions from 5.2 to 5.6.
Test script:
---------------
<?php
// date with leading zeros
$d = '1990-01-02';
// format without leading zeros
$f = 'Y-n-j';
print_r(date_parse_from_format($f, $d));
print_r(date_create_from_format($f, $d));
print_r(DateTime::getLastErrors());
echo '--------------------------';
// date without leading zeros
$d = '1990-1-2';
// format with leading zeros
$f = 'Y-m-d';
print_r(date_parse_from_format($f, $d));
print_r(date_create_from_format($f, $d));
print_r(DateTime::getLastErrors());
?>
Expected result:
----------------
Expect some warnings at least.
Actual result:
--------------
Array
(
[year] => 1990
[month] => 1
[day] => 2
[hour] =>
[minute] =>
[second] =>
[fraction] =>
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 0
[errors] => Array
(
)
[is_localtime] =>
)
DateTime Object
(
[date] => 1990-01-02 05:00:38.000000
[timezone_type] => 3
[timezone] => America/New_York
)
Array
(
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 0
[errors] => Array
(
)
)
--------------------------
Array
(
[year] => 1990
[month] => 1
[day] => 2
[hour] =>
[minute] =>
[second] =>
[fraction] =>
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 0
[errors] => Array
(
)
[is_localtime] =>
)
DateTime Object
(
[date] => 1990-01-02 05:00:38.000000
[timezone_type] => 3
[timezone] => America/New_York
)
Array
(
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 0
[errors] => Array
(
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71728&edit=1
Thread (3 messages)