Bug #70129 [Opn->Nab]: setISODate and format 'w' and 'W' are incompatible

From: Date: Fri, 24 Jul 2015 22:38:18 +0000
Subject: Bug #70129 [Opn->Nab]: setISODate and format 'w' and 'W' are incompatible
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194696@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70129&edit=1

 ID:                 70129
 Updated by:         cmb@php.net
 Reported by:        joydragon at gmail dot com
 Summary:            setISODate and format 'w' and 'W' are incompatible
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 PHP Version:        7.0.0beta2
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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'.


Previous Comments:
------------------------------------------------------------------------
[2015-07-24 14:20:10] 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



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



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


Thread (2 messages)

« previous php.bugs (#194696) next »