|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-04-25 09:25 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 13:00:01 2025 UTC |
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.