From: jennifer dot kimball at nrc dot ca
Operating system: Solaris 10
PHP version: 5.3.0
PHP Bug Type: Date/time related
Bug description: DatePeriod doesn't accept negative intervals
Description:
------------
DatePeriod should be able to create a list of dates that goes into the
future from the start date, or into the past from the start date. There is
nothing in the documentation to suggest this should not be possible, and
trying it does not throw an error.
Given that a question like 'What are the dates of the previous 3
Saturdays' is fairly common, it seems sensible that DatePeriod be able to
calculate that way.
Reproduce code:
---------------
---
>From manual page: dateperiod.construct#Description
---
//postive interval works:
$d1=date_create('2004-12-25');
$i=DateInterval::createFromDateString('1 year');
$d2=date_create('2009-03-03');
$p=new DatePeriod($d1,$i,$d2);
foreach($p as $d) echo $d->format('Y-m-d');
//negative interval fails with no error
$d1=date_create('2009-12-25');
$i=DateInterval::createFromDateString('-1 year');
$d2=date_create('2004-03-03');
$p=new DatePeriod($d1,$i,$d2);
foreach($p as $d) echo $d->format('Y-m-d');
Expected result:
----------------
//postive interval output (which does happen)
2004-12-25
2005-12-25
2006-12-25
2007-12-25
2008-12-25
//negative interval output (which does not happen)
2009-12-25
2008-12-25
2007-12-25
2006-12-25
2005-12-25
2004-12-25
Actual result:
--------------
//no output
//no error
--
Edit bug report at http://bugs.php.net/?id=50019&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=50019&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=50019&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=50019&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=50019&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=50019&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=50019&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=50019&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=50019&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=50019&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=50019&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=50019&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=50019&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=50019&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=50019&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50019&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50019&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=50019&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=50019&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=50019&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=50019&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=50019&r=mysqlcfg