#2709: Time Helper format method should allow for custom handling of invalid 
dates
----------------------------------------------------------------------+-----
    Reporter:  bparise                                                |         
Owner:          
        Type:  Enhancement                                            |        
Status:  reopened
    Priority:  Low                                                    |     
Milestone:  1.2.x.x 
   Component:  Helpers                                                |       
Version:  RC1     
    Severity:  Normal                                                 |    
Resolution:          
    Keywords:  timeHelper format invalid date bparise phpnut Lou2401  |   
Php_version:  PHP 5   
Cake_version:                                                         |  
----------------------------------------------------------------------+-----
Changes (by Lou2401):

  * status:  closed => reopened
  * resolution:  fixed =>

Comment:

 Sorry to reopen this ticket again, but the last solution is still not
 really sufficient. The problem is when you pass over a empty (NULL) $date
 content (coming out of a database request). The time helper function
 format uses its function fromString and there it uses the PHP function
 strtotime which results to a error because the function is used with an
 empty string ($date = NULL).

 To make time->format finally working I have changed for me the
 time->fromString function as follows:


 {{{
 function fromString($dateString, $userOffset = null) {
                 if (empty($dateString)) return false;
                 if (is_integer($dateString) || is_numeric($dateString)) {
                         $date = intval($dateString);
                 } else {
                         $date = strtotime($dateString);
                 }
                 if ($userOffset !== null) {
                         return $this->convert($date, $userOffset);
                 }
                 return $date;
 }}}

 As you can see I have only added one row

 {{{
 if (empty($dateString)) return false;
 }}}

 which cancels the function when the date string is empty.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/2709#comment:6>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

  • Re: [CakePHP : The Rapid... CakePHP : The Rapid Development Framework for PHP

Reply via email to