php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73942 $date->modify('Friday this week') doesn't return a Friday if $date is a Sunday
Submitted: 2017-01-16 01:37 UTC Modified: 2017-02-12 20:20 UTC
From: blindcan at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.0.14 OS: Ubuntu 16.04
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: blindcan at gmail dot com
New email:
PHP Version: OS:

 

 [2017-01-16 01:37 UTC] blindcan at gmail dot com
Description:
------------
As the summary says, $date->modify('Friday this week') doesn't return a Friday if $date is a Sunday.

Running the script below on 7.0.14 and 7.0.8 yields 2017-01-02, which is a Monday.

However, running the same script on 7.0.5 yields 2017-01-13, a Friday. I expected a Friday.

Test script:
---------------
<?php

$date1 = "2017-01-08"; // this is a Sunday
$date = new \DateTime($date1);
$date->modify('Friday this week');
$dateFormat = $date->format('Y-m-d');
echo $dateFormat;

Expected result:
----------------
Currently, it displays a Monday date on 7.0.14. Testing on 7.0.8 also yields a Monday.

I expect to see a Friday date on both PHP 7.0.5, and 7.0.14.

Here's another link that tests for all php versions and other base days - https://3v4l.org/ZuOhl


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-16 07:40 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2017-01-16 07:40 UTC] requinix@php.net
Looks like a duplicate of bug #72719.
 [2017-02-12 20:20 UTC] derick@php.net
-Status: Duplicate +Status: Closed -Assigned To: +Assigned To: derick
 [2017-02-12 20:20 UTC] derick@php.net
The fix for this bug has been committed.

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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 08:01:28 2024 UTC