Bug #78080 [Asn->Nab]: strtotime('last <day of week> + 7 days') incorrect result

From: Date: Fri, 22 Jul 2022 16:39:10 +0000
Subject: Bug #78080 [Asn->Nab]: strtotime('last <day of week> + 7 days') incorrect result
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241987@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78080&edit=1

 ID:                 78080
 Updated by:         derick@php.net
 Reported by:        romash1408 at yandex dot ru
 Summary:            strtotime('last <day of week> + 7 days') incorrect
                     result
-Status:             Assigned
+Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 Operating System:   UNIX
 PHP Version:        7.3.5
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

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

Having multiple stanzas working on the same field (the day) can not always be directly interpreted.
In this case, the "last wednesday" and "+x day" simply conflict. In order to
handle this correctly, you should split these stanzas up, like in:

echo (new DateTimeImmutable("2019-05-29"))->modify("last
wednesday")->modify("+7 days")->format("Y-m-d"), "\n";

Which will output:
2019-05-29


Previous Comments:
------------------------------------------------------------------------
[2021-07-30 12:27:54] cmb@php.net

Related To: Bug #78827

------------------------------------------------------------------------
[2021-07-30 12:27:53] cmb@php.net

Related To: Bug #78827

------------------------------------------------------------------------
[2020-01-20 17:28:05] girgias@php.net

Related to Bug #78827

------------------------------------------------------------------------
[2019-12-01 14:40:01] leo dot sjoberg at gmail dot com

PR open at timelib: https://github.com/derickr/timelib/pull/71

------------------------------------------------------------------------
[2019-05-29 03:29:20] romash1408 at yandex dot ru

Description:
------------
Today is 2019-05-29, wednesday.
In any php 7.* interpreter I write
echo date('Y-m-d', strtotime('last wednesday'));
and get last week's day (2019-05-22)

echo date('Y-m-d', strtotime('last wednesday + 1 day'));
shows correct date too (2019-05-23)

But
echo date('Y-m-d', strtotime('last wednesday + 7 day'));
gives result like 'last wednesday' was today (2019-06-05)

Live example on Ideone: https://ideone.com/1YzDpS

php 5.6 doesn't have this bug!

Test script:
---------------
$day = date("l");
echo date("Y-m-d", strtotime("last $day")) . "\n";
echo date("Y-m-d", strtotime("last $day + 1 day")) . "\n";
echo date("Y-m-d", strtotime("last $day + 6 day")) . "\n";
echo date("Y-m-d", strtotime("last $day + 7 day")) . "\n";


Expected result:
----------------
2019-05-21
2019-05-22
2019-05-27
2019-05-28

Actual result:
--------------
2019-05-21
2019-05-22
2019-05-27
2019-06-04


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78080&edit=1


Thread (4 messages)

« previous php.bugs (#241987) next »