Bug #66018 [NEW]: incorrect years for DateTime objects created with certain bad month names
From: kaldari at gmail dot com
Operating system: MacOS X
PHP version: 5.5.5
Package: Date/time related
Bug Type: Bug
Bug description:incorrect years for DateTime objects created with certain bad month names
Description:
------------
DateTime objects created with month names that have any letter appended
(other than 'j', 'J', 'I', 'V', or 'X'), and fall
between the years 2000
and 2059, default to the current year rather than showing the specified
year or throwing an error.
The following strings result in incorrect years:
'9 Junn 2000' -> 9 Jun 2013
'9 XZ 2014' -> 9 Oct 2013
'9 Decemberi 2020' -> 9 Dec 2013
However, both of the following give the correct year:
'9 Decemberi 1999' -> 9 Dec 1999
'9 Decemberi 2060' -> 9 Dec 2060
And all of the following throw an error (which seems sensible):
'9 Decemberj 1999' -> Error
'9 DECJ 2060' -> Error
'9 DECI 2060' -> Error
'9 DECX 2060' -> Error
PHP seems to interpret an appended 'j' or 'J' as a timezone indicator
(?!), and 'I', 'V' and 'X' are valid Roman month names, so they
trigger
a duplicate month error.
The mystery is why PHP doesn't error out in the other cases (and why the
years 2000 to 2059 affect the interpretation differently).
This bug blocks the following MediaWiki bug:
https://bugzilla.wikimedia.org/show_bug.cgi?id=33579
Test script:
---------------
$tz = new DateTimeZone("Europe/Amsterdam");
$dateObject = new DateTime( '9 junn 2000', $tz );
echo $dateObject->format( 'Y' );
$dateObject = new DateTime( '9 XZ 2014', $tz );
echo $dateObject->format( 'Y' );
$dateObject = new DateTime( '9 decemberi 2020', $tz );
echo $dateObject->format( 'Y' );
Expected result:
----------------
Error or 2000
Error or 2014
Error or 2020
Actual result:
--------------
2013 (current year)
2013 (current year)
2013 (current year)
--
Edit bug report at https://bugs.php.net/bug.php?id=66018&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66018&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66018&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66018&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66018&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66018&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66018&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66018&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66018&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66018&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66018&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66018&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66018&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66018&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66018&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66018&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66018&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66018&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66018&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66018&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66018&r=mysqlcfg
Thread (4 messages)
- kaldari at gmail dot com