Bug #74249 [NEW]: Instance created using "first day of ..." locks the day

From: Date: Wed, 15 Mar 2017 09:35:49 +0000
Subject: Bug #74249 [NEW]: Instance created using "first day of ..." locks the day
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207847@lists.php.net to get a copy of this message
From: peehaa Operating system: PHP version: Irrelevant Package: Date/time related Bug Type: Bug Bug description:Instance created using "first day of ..." locks the day Description: ------------ After initializing a new DateTime object using "first day of this ..." DateTime::setDate() doesn't correctly set the day anymore. It will always result 1. $date1 = new \DateTime('first day of this month'); echo $date1->format('Y-m-d') . "\n"; // correct: 2017-03-01 $date1->setDate(2017, 1, 8); echo $date1->format('Y-m-d') . "\n"; // wrong: 2017-01-01 I tried several things like "first day of january" and "first day of this month". https://3v4l.org/I2maQ Test script: --------------- <?php $date1 = new \DateTime('first day of this month'); echo $date1->format('Y-m-d') . "\n"; $date1->setDate(2016, 1, 8); echo $date1->format('Y-m-d') . "\n"; $date2 = new \DateTime('first day of january'); echo $date2->format('Y-m-d') . "\n"; $date2->setDate(2016, 3, 8); echo $date2->format('Y-m-d') . "\n"; Expected result: ---------------- 2017-03-01 2016-01-08 2017-01-01 2016-03-08 Actual result: -------------- 2017-03-01 2016-01-01 2017-01-01 2016-03-01 -- Edit bug report at https://bugs.php.net/bug.php?id=74249&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74249&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74249&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74249&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74249&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74249&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74249&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74249&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74249&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74249&r=support Expected behavior: https://bugs.php.net/fix.php?id=74249&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74249&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74249&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74249&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74249&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74249&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74249&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74249&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74249&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74249&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74249&r=mysqlcfg

« previous php.bugs (#207847) next »