Bug #75524 [Nab]: last monday this week working wrong
| From: | padre dot cedano at gmail dot com | Date: | Wed, 15 Nov 2017 03:27:35 +0000 |
| Subject: | Bug #75524 [Nab]: last monday this week working wrong | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212590@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75524&edit=1
ID: 75524
User updated by: padre dot cedano at gmail dot com
Reported by: padre dot cedano at gmail dot com
Summary: last monday this week working wrong
Status: Not a bug
Type: Bug
Package: Date/time related
PHP Version: 7.0.25
Block user comment: N
Private report: N
New Comment:
Ok. My function is working as:
function getLastDayofWeek ($strDia){
$date=new DateTime('now');
$strCriterio='last '.$strDia;
$d=$date->modify($strCriterio);
echo $strCriterio.":\t ".$d->format('d/m/Y').PHP_EOL;
}
Result:
last monday: 13/11/2017
last tuesday: 14/11/2017
last wednesday: 08/11/2017
last thursday: 09/11/2017
last friday: 10/11/2017
last saturday: 11/11/2017
last sunday: 12/11/2017
But is not working if i pass the $date as parameter:
function getLastDayofWeekFake ($strDia,$date){
$strCriterio='last '.$strDia;
$d=$date->modify($strCriterio);
echo $strCriterio.":\t ".$d->format('d/m/Y').PHP_EOL;
}
Result:
last monday: 13/11/2017
last tuesday: 07/11/2017
last wednesday: 01/11/2017
last thursday: 26/10/2017
last friday: 20/10/2017
last saturday: 14/10/2017
last sunday: 08/10/2017
Why is not working in second function?
Previous Comments:
------------------------------------------------------------------------
[2017-11-14 17:04:23] danack@php.net
I really doubt this is a bug.
Doing 'monday this week' is not only clearer english, but also gives you the result you
want, I think.
https://3v4l.org/UYsNE
'last monday this week' - means from the start of this week, find the previous monday. Not
find the monday of this week.
------------------------------------------------------------------------
[2017-11-14 16:45:21] padre dot cedano at gmail dot com
Previuos package error
------------------------------------------------------------------------
[2017-11-14 16:44:07] padre dot cedano at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetime.modify
---
If i try this today, 2o17-11-14:
modify('last monday this week')
the result is:
06/11/2017
But last monday this week was:
13/11/2017
Test script:
---------------
<?php
function getLastDayofWeek ($strDia){
$date=new DateTime('now');
$strCriterio='last '.$strDia.' this week';
$date->modify($strCriterio);
echo $strCriterio.": ".$date->format('d/m/Y').PHP_EOL;
}
/*Pruebas*/
getLastDayofWeek('monday');
getLastDayofWeek('saturday');
getLastDayofWeek('sunday');
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75524&edit=1