Bug #77941 [ReO->Nab]: strtotime "next <weekday>" are off by one for dates parsed from calendar week

From: Date: Fri, 22 Jul 2022 16:29:45 +0000
Subject: Bug #77941 [ReO->Nab]: strtotime "next <weekday>" are off by one for dates parsed from calendar week
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241986@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77941&edit=1

 ID:                 77941
 Updated by:         derick@php.net
 Reported by:        mail at cebe dot cc
 Summary:            strtotime "next <weekday>" are off by one for dates
                     parsed from calendar week
-Status:             Re-Opened
+Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        7.3.4
 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

The combination of the "yyyyWww" and "x dayname" stanzas is not supported.

However, in order to find the Friday of a week, you can use "yyyyWww-d", such as
"2019W16-5". We can't support every string that you throw at the parser :-).


Previous Comments:
------------------------------------------------------------------------
[2019-06-14 11:52:02] sjon@php.net

Related To: Bug #77999

------------------------------------------------------------------------
[2019-04-25 21:17:45] cmb@php.net

Seems I closed this too quick – sorry.  Re-opening.

------------------------------------------------------------------------
[2019-04-25 21:04:51] a at b dot c dot de

How would using the ISO year make a difference in the middle of April? And why would it cause a
shift of one day?

Consider
echo date("o-W-N", strtotime("2019W16 next tuesday"));

Between 5.1.6 and 5.2.0 the output changes from Tuesday of Week 16 (2019-16-2) to Monday of Week 17
(2019-17-1).

Tuesday isn't Monday even in the ISO calendar.

------------------------------------------------------------------------
[2019-04-25 13:21:34] cmb@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

You have to use 'o' in combination with 'W'.

------------------------------------------------------------------------
[2019-04-25 09:25:25] mail at cebe dot cc

Description:
------------
when working on a date parsed from calendar week from the pattern {YYYY}W{WW}, e.g.
"2019W16" strtotime returns the date of Monday in the calendar week 16 in the year 2019,
which is 2019-04-15.

When this is combinated with a "next <weekday>" e.g. "2019W16 next
friday", the result is one off, in this case 2019-04-18, which is Thursday of that week, not
Friday.

Giving "2019-04-15 next friday" gives the correct date: 2019-04-19.

According to my test script, this is broken since PHP 5.2, while working fine in 5.1: https://3v4l.org/0s4Ns

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

// see also https://3v4l.org/0s4Ns

if (function_exists('date_default_timezone_set'))
date_default_timezone_set("UTC");
echo "works as expected:\n";
echo date("Y-m-d H:i:s", strtotime("2019W14")) . " should be
2019-04-01\n";
echo date("Y-m-d H:i:s", strtotime("2019W15")) . " should be
2019-04-08\n";
echo date("Y-m-d H:i:s", strtotime("2019W16")) . " should be
2019-04-15\n\n";

echo "off by one:\n";
echo date("Y-m-d H:i:s", strtotime("2019W16 next tuesday")) . " should be
2019-04-16\n";
echo date("Y-m-d H:i:s", strtotime("2019W16 next wednesday")) . " should be
2019-04-17\n";
echo date("Y-m-d H:i:s", strtotime("2019W16 next thursday")) . " should be
2019-04-18\n";
echo date("Y-m-d H:i:s", strtotime("2019W16 next friday")) . " should be
2019-04-19\n";
echo date("Y-m-d H:i:s", strtotime("2019W16 next saturday")) . " should be
2019-04-20\n";
echo date("Y-m-d H:i:s", strtotime("2019W16 next sunday")) . " should be
2019-04-21\n";
echo date("Y-m-d H:i:s", strtotime("2019W16 next monday")) . " should be
2019-04-22\n\n";

echo "works as expected:\n";
echo date("Y-m-d H:i:s", strtotime("2019-04-15 next monday")) . " should be
2019-04-22\n";
echo date("Y-m-d H:i:s", strtotime("2019-04-15 next friday")) . " should be
2019-04-19\n";
echo date("Y-m-d H:i:s", strtotime("2019-04-15 next thursday")) . " should
be 2019-04-18\n";

Expected result:
----------------
see above.

Actual result:
--------------
see above.


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



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


Thread (5 messages)

« previous php.bugs (#241986) next »