Bug->Doc #72586 [Ver]: wrong createfromformat for leap year

From: Date: Sun, 12 Feb 2017 20:33:41 +0000
Subject: Bug->Doc #72586 [Ver]: wrong createfromformat for leap year
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14435@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72586&edit=1 ID: 72586 Updated by: derick@php.net Reported by: stierlitz122 at gmail dot com Summary: wrong createfromformat for leap year Status: Verified -Type: Bug +Type: Documentation Problem -Package: Date/time related +Package: *Directory/Filesystem functions Operating System: ubuntu/windows PHP Version: 5.6.23 Block user comment: N Private report: N New Comment: createFromFormat parses data from left to right, turning them into Y-m-d (& H:i:s) values. In this case, when it sees the "59" it assumes the year is 2017 (the current year) (March 1st). When it is than re-expressed for 2016, the value becomes 60 (as March 1st is the 60th day in a leap year). As 29-02-2016 and 2016-02-29 always means the same, there is no discrepancy here. The documentation isn't quite clear on this parsing order, but it hints at that through the ! and + modifiers. So I am marking this as a documentation issue. Previous Comments: ------------------------------------------------------------------------ [2016-07-12 19:02:22] cmb@php.net Confirmed: <https://3v4l.org/ei8A2>. ------------------------------------------------------------------------ [2016-07-12 16:09:14] stierlitz122 at gmail dot com Description: ------------ When using day of the year character 'z' with 'Y' for creation date - order is important, but not important when using 'd-m-Y'. --- From manual page: http://www.php.net/datetime.createfromformat --- Test script: --------------- <?php $date1 = DateTime::createFromFormat('z Y', "59 2016"); //wrong with leap year $date2 = DateTime::createFromFormat('Y z', "2016 59"); //correct $date3 = DateTime::createFromFormat('d-m-Y', "29-02-2016"); //correct $date4 = DateTime::createFromFormat('Y-m-d', "2016-02-29"); //correct // let's see: print $date1->format("z Y")."\n"; //60 2016 print $date2->format("z Y")."\n"; //59 2016 print $date3->format("z Y")."\n"; //59 2016 print $date4->format("z Y")."\n"; //59 2016 Expected result: ---------------- 59 2016 59 2016 59 2016 59 2016 Actual result: -------------- 60 2016 59 2016 59 2016 59 2016 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72586&edit=1

« previous php.doc.bugs (#14435) next »