php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46874 DatePeriod not resetting after foreach loop
Submitted: 2008-12-15 20:55 UTC Modified: 2010-08-30 17:35 UTC
From: php at michaelcrumley dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.0alpha3 OS: WIN32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at michaelcrumley dot com
New email:
PHP Version: OS:

 

 [2008-12-15 20:55 UTC] php at michaelcrumley dot com
Description:
------------
After looping through a DatePeriod object, the current date is not reset so looping again starts at the same date. Maybe that is the intended behavior, but I would expect it to start at the same date each time.


Reproduce code:
---------------
$dp = new DatePeriod('R5/2008-03-01T13:00:00Z/P1Y2M10DT2H30M');

foreach ($dp as $date) {
    echo $date->format("Y-m-d H:i:s\n");
}

echo "\n";

// this should repeat the same range
foreach ($dp as $date) {
    echo $date->format("Y-m-d H:i:s\n");
}


Expected result:
----------------
2008-03-01 13:00:00
2009-05-11 15:30:00
2010-07-21 18:00:00
2011-10-01 20:30:00
2012-12-11 23:00:00
2014-02-22 01:30:00

2008-03-01 13:00:00
2009-05-11 15:30:00
2010-07-21 18:00:00
2011-10-01 20:30:00
2012-12-11 23:00:00
2014-02-22 01:30:00


Actual result:
--------------
2008-03-01 13:00:00
2009-05-11 15:30:00
2010-07-21 18:00:00
2011-10-01 20:30:00
2012-12-11 23:00:00
2014-02-22 01:30:00

2015-05-02 04:00:00
2016-07-12 06:30:00
2017-09-22 09:00:00
2018-12-02 11:30:00
2020-02-12 14:00:00
2021-04-22 16:30:00


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-16 09:11 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2010-08-30 17:35 UTC] derick@php.net
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&revision=302888
Log: - Added test for bug #46874 (same as #52668).
 [2010-08-30 17:35 UTC] derick@php.net
-Status: Bogus +Status: Closed -Assigned To: +Assigned To: derick
 [2010-08-30 17:35 UTC] derick@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

(And duplicate of #53668)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 18:01:29 2024 UTC