Req #50019 [Opn->Nab]: DatePeriod doesn't accept negative intervals

From: Date: Wed, 11 Jan 2017 17:02:33 +0000
Subject: Req #50019 [Opn->Nab]: DatePeriod doesn't accept negative intervals
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206527@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 Updated by: heiglandreas@php.net Reported by: jennifer dot kimball at nrc dot ca Summary: DatePeriod doesn't accept negative intervals -Status: Open +Status: Not a bug 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: As the requested feature works pretty well when instantiating the DatePeriod-Object with start and end[1] and with start and recurrences[2] When instantiating it with a start that is higher than the end it is intended behaviour that no output is generated. I'm closing this issue therefore. [1] https://3v4l.org/ucso1 [2] https://3v4l.org/GSOpu Previous Comments: ------------------------------------------------------------------------ [2016-06-12 10:48:14] cmb@php.net Given that negative DateIntervals are allowed and date-time arithmetic is supported[1], that appears to be a reasonable request. [1] <https://3v4l.org/ufYCh> ------------------------------------------------------------------------ [2011-10-12 16:33:04] dagguh at gmail dot com 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 :) ------------------------------------------------------------------------ [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

« previous php.bugs (#206527) next »