Bug #70129 [NEW]: setISODate and format 'w' and 'W' are incompatible
From: joydragon at gmail dot com
Operating system:
PHP version: 7.0.0beta2
Package: Date/time related
Bug Type: Bug
Bug description:setISODate and format 'w' and 'W' are incompatible
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 bug report at https://bugs.php.net/bug.php?id=70129&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70129&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70129&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70129&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70129&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70129&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70129&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70129&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70129&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70129&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70129&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70129&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70129&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70129&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70129&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70129&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70129&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70129&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70129&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70129&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70129&r=mysqlcfg
Thread (2 messages)
- joydragon at gmail dot com