Req #50019 [Com]: DatePeriod doesn't accept negative intervals

From: Date: Wed, 12 Oct 2011 16:33:05 +0000
Subject: Req #50019 [Com]: DatePeriod doesn't accept negative intervals
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-164261@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=50019&edit=1

 ID:                 50019
 Comment by:         dagguh at gmail dot com
 Reported by:        jennifer dot kimball at nrc dot ca
 Summary:            DatePeriod doesn't accept negative intervals
 Status:             Open
 Type:               Feature/Change Request
 Package:            Date/time related
 Operating System:   Solaris 10
 PHP Version:        5.3.0
 Block user comment: N
 Private report:     N

 New Comment:

You are mistaken.

This is the faulty line:
$i=DateInterval::createFromDateString('-1 year');

DateInterval::createFromDateString doesn't report any error when it fails. Fix 
your DateInterval first :)


Previous Comments:
------------------------------------------------------------------------
[2009-10-27 15:13:56] jennifer dot kimball at nrc dot ca

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 this bug report at https://bugs.php.net/bug.php?id=50019&edit=1


Thread (4 messages)

« previous php.bugs (#164261) next »