Bug #69468 [NEW]: DateTime->add problem for 2015-01-31
| From: | pawaroti at gmail dot com | Date: | Thu, 16 Apr 2015 10:37:17 +0000 |
| Subject: | Bug #69468 [NEW]: DateTime->add problem for 2015-01-31 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-192129@lists.php.net to get a copy of this message | ||
From: pawaroti at gmail dot com
Operating system: Windows 7
PHP version: 5.5.24RC1
Package: Date/time related
Bug Type: Bug
Bug description:DateTime->add problem for 2015-01-31
Description:
------------
Adding 1 month using DateInterval('P1M') sets date to 2015-03-03 if
adding from DateTime('2015-01-31')
+1 month = 2015-03-03
+2 months = 2015-03-31
+3 months = 2015-05-01
+4 months = 2015-05-31
+5 months = 2015-07-01
+6 months = 2015-07-31
+7 months = 2015-08-31
+8 months = 2015-10-01
+9 months = 2015-10-31
+10 months = 2015-12-01
+11 months = 2015-12-31
+12 months = 2016-01-31
BEFORE:
object(DateTime)[5]
public 'date' => string '2015-01-31 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Warsaw' (length=13)
AFTER
object(DateTime)[5]
public 'date' => string '2015-03-03 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Warsaw' (length=13)
INTERVAL
object(DateInterval)[6]
public 'y' => int 0
public 'm' => int 1
public 'd' => int 0
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 0
public 'days' => boolean false
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
Test script:
---------------
for($i=0; $i<=12; $i++)
{
$data = new DateTime('2015-01-31');
echo $data->add(new
DateInterval('P'.$i.'M'))->format('Y-m-d').'<br
/>';
}
Expected result:
----------------
2015-02-28
2015-03-31
2015-04-30
2015-05-31
2015-06-30
2015-07-31
2015-08-31
2015-09-30
2015-10-31
2015-11-30
2015-12-31
2016-01-31
Actual result:
--------------
2015-03-03
2015-03-31
2015-05-01
2015-05-31
2015-07-01
2015-07-31
2015-08-31
2015-10-01
2015-10-31
2015-12-01
2015-12-31
2016-01-31
--
Edit bug report at https://bugs.php.net/bug.php?id=69468&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69468&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69468&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69468&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69468&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69468&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69468&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69468&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69468&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69468&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69468&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69468&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69468&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69468&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69468&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69468&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69468&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69468&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69468&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69468&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69468&r=mysqlcfg