Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0a4

Bug #18136 Method setDay can create invalid date
Submitted: 2010-12-22 16:53 UTC
From: jcheng Assigned:
Status: Open Package: Date (version 1.4.7)
PHP Version: 5.3.4 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2010-12-22 16:53 UTC] jcheng (Johnny Cheng)
Description: ------------ Method setDay can create invalid date if we give a day that doesn't exist in the current month. Test script: --------------- $date = new Date('2010-02-15'); $date->setDay(31); echo $date->getDate(DATE_FORMAT_ISO); Expected result: ---------------- It's giving me 2010-02-31 but the returned date is not a valid one. I was expecting it to give me one of those valid dates : - 2010-02-28 - the date advanced by 31 days (2010-03-04). - the result of : echo date( 'Y-m-d', mktime(0, 0, 1, 2, 31, 2010) ); A possible patch would be : function setDay($d) { if ($d > 31 || $d < 1) { $this->day = 1; } else { $this->day = $this->getDaysInMonth() < $d ? $this->getDaysInMonth() : $d; } }

Comments

 [2010-12-22 17:05 UTC] jcheng (Johnny Cheng)
I've mistyped a possible result. Correction : "the date set to day 1 then advanced by 31 days (2010-03-04) instead of "the date advanced by 31 days (2010-03-04)"