Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/02/2012, 13:35
Avatar de JaimeMSE
JaimeMSE
 
Fecha de Ingreso: diciembre-2010
Ubicación: Isla Cristina (Huelva)
Mensajes: 164
Antigüedad: 13 años, 3 meses
Puntos: 7
Problema con una clase de fechas

Hola,

Hoy acabo de subir mi web a internet (de momento en un hosting de prueba gratuita) y me tira el siguiente error:

Fatal error: Call to undefined method haceTanto::diff() in /home/dvezeogs/public_html/config.php on line 49

Lo que hago es capturar la fecha de la base de datos y ponerla en el formato: "5 años, 4 meses y 19 días". Abajo os comento la linea que da el error.

Espero que me podáis ayudar. Muchas gracias de antemano.

Os pongo como llamo a la clase:
Código PHP:
Ver original
  1. <?php $hace = new haceTanto($row["fecha"]); ?>
  2. <span class="fichanegrita"><?php echo $lang_seccion_fichas['edad'] ?>:</span> <?php echo ''.$hace; ?><br/><br/>

Y os pongo el código completo de la clase:
Código PHP:
Ver original
  1. //Clase para obtener la fecha para la ficha de los animales
  2. class haceTanto extends DateTime {
  3.  
  4.     protected $strings = array(
  5.         'y' => array('1 a&ntilde;o, ', '%d a&ntilde;os, '),
  6.         'm' => array('1 mes y', '%d meses y'),
  7.         'd' => array('1 d&iacute;a', '%d dias'),
  8.     );
  9.  
  10.     public $profundidad;
  11.  
  12.     public function __construct( $fecha,$profundidad='i')
  13.     {
  14.         parent::__construct( $fecha );
  15.         $this->profundidad = $profundidad;
  16.  
  17.     }
  18.  
  19.  
  20.     public function __toString() {
  21.          try
  22.         {  
  23.             $now = new DateTime('now');
  24.             $diff = $this->diff($now); //ESTA ES LA LINEA QUE DA PROBLEMAS
  25.  
  26.             foreach($this->strings as $key => $value){
  27.  
  28.                 if( (@$text .= ' '.$this->getDiffText($key, $diff)) ){
  29.  
  30.                 }
  31.                 if($this->profundidad == $key) break;
  32.             }
  33.             return $text;  
  34.         }
  35.         catch(Exception $e)
  36.         {  
  37.             trigger_error($e->getMessage(), E_USER_ERROR);  
  38.             return '';  
  39.         }  
  40.  
  41.  
  42.     }
  43.  
  44.      protected function getDiffText($intervalKey, $diff){
  45.         $pluralKey = 1;
  46.         $value = $diff->$intervalKey;
  47.         if($value > 0){
  48.             if($value < 2){
  49.                 $pluralKey = 0;
  50.             }
  51.             return sprintf($this->strings[$intervalKey][$pluralKey], $value);
  52.         }
  53.         return null;
  54.     }
  55. }
__________________
@JaimeMSE - ¡Sígueme!