Bug #71728 [NEW]: date functions leading zeros ingnore

From: Date: Mon, 07 Mar 2016 10:08:17 +0000
Subject: Bug #71728 [NEW]: date functions leading zeros ingnore
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199639@lists.php.net to get a copy of this message
From:             shadowspawnshadow at gmail dot com
Operating system: Windows
PHP version:      5.5.33
Package:          Date/time related
Bug Type:         Bug
Bug description:date functions leading zeros ingnore

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 bug report at https://bugs.php.net/bug.php?id=71728&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71728&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71728&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71728&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71728&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71728&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71728&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71728&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71728&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71728&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71728&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71728&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71728&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71728&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71728&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71728&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71728&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71728&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71728&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71728&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71728&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#199639) next »