Bug #73298 [NEW]: DateTime::add adding 1 month on 31st of August skips to October
| From: | enachesilviu at live dot com | Date: | Wed, 12 Oct 2016 04:09:21 +0000 |
| Subject: | Bug #73298 [NEW]: DateTime::add adding 1 month on 31st of August skips to October | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-204617@lists.php.net to get a copy of this message | ||
From: enachesilviu at live dot com
Operating system: CentOS 6
PHP version: Irrelevant
Package: Date/time related
Bug Type: Bug
Bug description:DateTime::add adding 1 month on 31st of August skips to October
Description:
------------
DateTime::add adding 1 month on 31st of August skips to October
I did a similar snippet in Java and I get the expected result:
import java.util.*;
import java.text.*;
import java.lang.*;
class TestingDateTime
{
public static void main (String[] args) throws java.lang.Exception
{
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
Date date = ft.parse("2016-08-31");
System.out.println("Initial value:");
System.out.println(ft.format(date));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, 1);
date = calendar.getTime();
System.out.println("\nNew value:");
System.out.println(ft.format(date));
}
}
Test script:
---------------
<?php
function printline($value) {
$separator = 'cli' == php_sapi_name() ? PHP_EOL : '<br/>';
echo $value . $separator;
}
$dateTime = new DateTime('2016-08-31 00:00:00');
printline('Initial value: ' . $dateTime->format('Y-m-d H:i:s'));
$dateTime->add(new DateInterval('P1M'));
printline('New value: ' . $dateTime->format('Y-m-d H:i:s'));
Expected result:
----------------
2016-09-30 00:00:00
Actual result:
--------------
2016-10-01 00:00:00
--
Edit bug report at https://bugs.php.net/bug.php?id=73298&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73298&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73298&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73298&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73298&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73298&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73298&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73298&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73298&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73298&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73298&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73298&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73298&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73298&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73298&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73298&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73298&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73298&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73298&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73298&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73298&r=mysqlcfg