php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61642 modify("+5 weekdays") returns Sunday
Submitted: 2012-04-05 18:01 UTC Modified: 2012-08-06 02:26 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jeff at nd4c dot com Assigned: stas (profile)
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS: Fedora 14 and Windows 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jeff at nd4c dot com
New email:
PHP Version: OS:

 

 [2012-04-05 18:01 UTC] jeff at nd4c dot com
Description:
------------
Tested on Windows 7: 
  Apache/2.2.16 (Win32) PHP/5.3.5
Tested on Fedora 14: 
  Fedora release 14 (Laughlin) Linux 2.6.35.4-rscloud x86_64 
  php.x86_64 5.3.8-3.fc14
These are the latest stable versions I can find for these two systems.  (Especially since V6 binaries are no longer available for Windows.)
The Linux system is a live server using a framework that has not been tested with any later versions than 5.3.8

When modifying a DateTime instance with "+5 weekdays" it will return a date for a Sunday and not a weekday.

Running the Test script you note that the section for "5" returns Sunday.  All the other numbers are correct.  Note the pattern for skipping the weekends is always for Friday, Saturday and Sunday.  However for "+5" weekends should be skipped for Saturday, Sunday and Monday, which is different than for any other number.

Test script:
---------------
$days = array(1,2,3,4,5,6,7,8,);
$dates = array('2012-03-29','2012-03-30','2012-03-31','2012-04-01','2012-04-02','2012-04-03','2012-04-04','2012-04-05',);
foreach ($days as $businessdays)
{
	foreach ($dates as $startdate)
	{
		$start = new DateTime($startdate);
		$date = new DateTime($startdate);
		echo '<br/>'.$businessdays.' : '.$date->format('l').' : '.$date->format('Y-m-d');
		$date->modify("+{$businessdays} weekdays");
		echo ' : '.$date->format('Y-m-d').' : '.$date->format('l');
	}
	echo '<br/>';
}



Expected result:
----------------
...

5 : Thursday : 2012-03-29 : 2012-04-05 : Thursday
5 : Friday : 2012-03-30 : 2012-04-06 : Friday
5 : Saturday : 2012-03-31 : 2012-04-09 : Monday
5 : Sunday : 2012-04-01 : 2012-04-09 : Monday
5 : Monday : 2012-04-02 : 2012-04-09 : Monday
5 : Tuesday : 2012-04-03 : 2012-04-10 : Tuesday
5 : Wednesday : 2012-04-04 : 2012-04-11 : Wednesday
5 : Thursday : 2012-04-05 : 2012-04-12 : Thursday

...

Actual result:
--------------
...

5 : Thursday : 2012-03-29 : 2012-04-05 : Thursday
5 : Friday : 2012-03-30 : 2012-04-08 : Sunday
5 : Saturday : 2012-03-31 : 2012-04-08 : Sunday
5 : Sunday : 2012-04-01 : 2012-04-08 : Sunday
5 : Monday : 2012-04-02 : 2012-04-09 : Monday
5 : Tuesday : 2012-04-03 : 2012-04-10 : Tuesday
5 : Wednesday : 2012-04-04 : 2012-04-11 : Wednesday
5 : Thursday : 2012-04-05 : 2012-04-12 : Thursday

...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-11 15:56 UTC] zhanglijiu at gmail dot com
I check the php manual, there is no weekdays parameter for modify. So you have to 
use modify(+ n day) or modify(+ n week).
 [2012-04-11 16:11 UTC] jeff at nd4c dot com
The documentation is at:
http://www.php.net/manual/en/datetime.formats.relative.php

That page is linked to from:
http://www.php.net/manual/en/datetime.formats.php

Which is linked to from:
http://www.php.net/manual/en/datetime.modify.php
 [2012-08-06 02:25 UTC] stas@php.net
Automatic comment on behalf of johnnyspoon@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a6a7787cf25af0cf5b5672b677e20d9d40963137
Log: Fix #61642: modify(&quot;+5 weekdays&quot;) returns Sunday
 [2012-08-06 02:26 UTC] stas@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/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

fixed in master
 [2012-08-06 02:26 UTC] stas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2013-11-17 09:32 UTC] laruence@php.net
Automatic comment on behalf of johnnyspoon@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a6a7787cf25af0cf5b5672b677e20d9d40963137
Log: Fix #61642: modify(&quot;+5 weekdays&quot;) returns Sunday
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC