php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70129 setISODate and format 'w' and 'W' are incompatible
Submitted: 2015-07-24 14:20 UTC Modified: 2015-07-24 22:38 UTC
From: joydragon at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: 7.0.0beta2 OS:
Private report: No CVE-ID: None
 [2015-07-24 14:20 UTC] joydragon at gmail dot com
Description:
------------
I've encountered an inconsistency on the processing of the week numbers on the setISODate method for the DateTime object
Because of the week and day of the week number arrangement you can get a borderline case to get inconsistent. I've tested it on my 5.6.10 version of php and on an online 7.0.0beta2 version on the next link
http://viper-7.com/G77zZ0
If you change the initial date stored on the $now variable to a day that's not the end of the week it works fine, but otherwise it will return a day prior to the current $now time.

Test script:
---------------
        $regex = '/^(\d)\s+(\d\d):(\d\d)(:\d\d)?$/';            // 0 12:00
        $data = "1 12:00";
        if(preg_match($regex, $data, $matches)) {
            $now = new \DateTime("2015-07-12 02:00:00");
            var_dump($now->format('c'));
            $weekDay = intval($now->format("w"));
            $weekNumber = intval($now->format("W"));
            $year = intval($now->format("Y"));
            if($matches[1] > $weekDay){
                $now->setISODate($year, $weekNumber, $matches[1]);
                $now->setTime($matches[2], $matches[3]);
            }
            else if($matches[1] <= $weekDay){
                $now->setISODate($year, $weekNumber+1, $matches[1]);
                $now->setTime($matches[2], $matches[3]);
            }
            var_dump($now->format('c'));
        }

Expected result:
----------------
It should return 2015-07-13T12:00:00+00:00


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-24 22:38 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-07-24 22:38 UTC] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

If you want to get the ISO-8601 conforming day of the week, you
have to use 'N' and not 'w'.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 22:01:31 2024 UTC