Documentación GVHIDRA 3.1.5
Referencia de la Clase gvHidraTimestamp

Métodos públicos

 __construct ($ts='now', $tz=null)
 __sleep ()
 __wakeup ()
 setTime ($hours, $minutes, $seconds=0)
 setDate ($year, $month, $day)
 modify ($str)
 formatUser ()
 formatFW ()
 formatSOAP ()
 getTimestamp ()
 between ($date1, $date2)
 betweenDays ($date1, $numDays)
 addDays ($numDays)
 subDays ($numDays)
 addWeeks ($numWeeks)
 subWeeks ($numWeeks)
 addMonths ($numMonths)
 subMonths ($numMonths)
 addYears ($numYears)
 subYears ($numYears)
 isLeap ()

Métodos públicos estáticos

static cmp ($date1, $date2)
static outputFormat ($fmt)

Métodos protegidos

 checkLastDayOfMonth ()

Atributos protegidos

 $_year
 $_month
 $_day

Métodos privados

 init ()

Atributos privados

 $_date_time

Descripción detallada

Definición en la línea 43 del archivo gvHidraTimestamp.php.


Documentación del constructor y destructor

__construct ( ts = 'now',
tz = null 
)

METODOS SOBRECARGADOS Sobreescribe el constructor por defecto

Definición en la línea 57 del archivo gvHidraTimestamp.php.

                                                  {
                if (is_null($tz))
                        parent::__construct($ts);
                else
                        parent::__construct($ts,$tz);

                $this->init();
        }

Documentación de las funciones miembro

__sleep ( )

Usado junto con __wakeup para conservar estado de clase base DateTime

TODO: Segun explica en http://php.net/manual/en/datetime.wakeup.php (comentario del 19-Jun-2009 03:14 parece que con la 5.3 se arregla.

Definición en la línea 72 del archivo gvHidraTimestamp.php.

                                  {
                $this->_date_time = $this->format('c');
                return array('_date_time','_year','_month','_day');
        }
__wakeup ( )

Usado junto con __sleep para conservar estado de clase base DateTime

Definición en la línea 80 del archivo gvHidraTimestamp.php.

                                   {
                $this->__construct($this->_date_time);
        }
addDays ( numDays)

METODOS PARA OPERAR

Definición en la línea 234 del archivo gvHidraTimestamp.php.

                                          {
                if (!is_numeric($numDays) || $numDays < 1) {
                        throw new Exception('addDays() espera un entero positivo');
                }
                $this->modify('+' . intval($numDays) . ' days');
        }
addMonths ( numMonths)

Este mtodo cambia el funcionamiento por defecto usado en modify:

  • si estamos en dia 31 y le sumamos un mes, si no existe el dia obtenemos el 1 del mes siguiente Con este metodo, en la situacin anterior obtenemos el ltimo dia del mes siguiente.

Definición en la línea 267 del archivo gvHidraTimestamp.php.

                                              {
                if (!is_numeric($numMonths) || $numMonths < 1) {
                        throw new Exception('addMonths() espera un entero positivo');
                }
                $numMonths = (int) $numMonths;
                // Add the months to the current month number.
                $newValue = $this->_month + $numMonths;
                // If the new value is less than or equal to 12, the year
                // doesn't change, so just assign the new value to the month.
                if ($newValue <= 12) {
                        $this->_month = $newValue;
                } else {
                        // A new value greater than 12 means calculating both
                        // the month and the year. Calculating the year is
                        // different for December, so do modulo division
                        // by 12 on the new value. If the remainder is not 0,
                        // the new month is not December.
                        $notDecember = $newValue % 12;
                        if ($notDecember) {
                                // The remainder of the modulo division is the new month.
                                $this->_month = $notDecember;
                                // Divide the new value by 12 and round down to get the
                                // number of years to add.
                                $this->_year += floor($newValue / 12);
                        } else {
                                // The new month must be December
                                $this->_month = 12;
                                $this->_year += ($newValue / 12) - 1;
                        }
                }
                $this->checkLastDayOfMonth();
                parent::setDate($this->_year, $this->_month, $this->_day);
        }
addWeeks ( numWeeks)

Definición en la línea 248 del archivo gvHidraTimestamp.php.

                                            {
                if (!is_numeric($numWeeks) || $numWeeks < 1) {
                        throw new Exception('addWeeks() espera un entero positivo');
                }
                $this->modify('+' . intval($numWeeks) . ' weeks');
        }
addYears ( numYears)

Ver comentarios en addMonths

Definición en la línea 338 del archivo gvHidraTimestamp.php.

                                            {
                if (!is_numeric($numYears) || $numYears < 1) {
                        throw new Exception('addYears() espera un entero positivo');
                }
                $this->_year += (int) $numYears;
                $this->checkLastDayOfMonth();
                parent::setDate($this->_year, $this->_month, $this->_day);
        }
between ( date1,
date2 
)

Devuelve si la fecha actual est entre el rango de fechas introducido REVIEW: Hay que revisar este metodo. La forma de trabajar con el no se si es comoda. Ahora que se puede comparar directamente, igual ya tiene poco sentido

Definición en la línea 188 del archivo gvHidraTimestamp.php.

                                                {
                if ($this >= $date1 and $this <= $date2)
                        return true;
                return false;
        }
betweenDays ( date1,
numDays 
)

Definición en la línea 194 del archivo gvHidraTimestamp.php.

                                                      {
                if (!is_numeric($numDays))
                        throw new Exception('betweenDays() espera un entero');

                $date2 = clone $date1;
                if ($numDays > 0) {
                        $date2->addDays($numDays);
                        return $this->between($date1,$date2);
                } else {
                        $date2->subDays($numDays);
                        return $this->between($date2,$date1);
                }
        }
checkLastDayOfMonth ( ) [final, protected]

Comprueba si la fecha interna calculada en metodos addMonths, subMonths, ... es correcta. En estos mtodos solo se cambia el mes y ao, por lo que slo hay que comprobar que el dia siga existiendo en el mes-ao en curso, y en caso contrario ajusta el da al ltimo del mes

Definición en la línea 364 del archivo gvHidraTimestamp.php.

                                                       {
                if (!checkdate($this->_month, $this->_day, $this->_year)) {
                        $use30 = array(4 , 6 , 9 , 11);
                        if (in_array($this->_month, $use30)) {
                                $this->_day = 30;
                        } else {
                                $this->_day = $this->isLeap() ? 29 : 28;
                        }
                }
        }
static cmp ( date1,
date2 
) [static]

Compara dos objetos fecha Devuelve 1 si la primera es menor, -1 si es mayor, y 0 si son iguales Como la comparacin se puede hacer directamente, este metodo ya no tiene mucho sentido

Definición en la línea 213 del archivo gvHidraTimestamp.php.

                                                   {
                if ($date1 > $date2)
                        return -1;
                if ($date1 < $date2)
                        return 1;
                return 0;
        }
formatFW ( )

Formatea la fecha en el formato FW

Definición en la línea 156 del archivo gvHidraTimestamp.php.

                                   {
                $fmt = ConfigFramework::getDateMaskFW();
                //$fmt = $this->outputFormat($fmt);
                $fhora = $this->format('His')!='000000'? ' '.ConfigFramework::getTimeMask(): '';
                return $this->format($fmt.$fhora);
        }
formatSOAP ( )

Formatea la fecha en el formato usado por SOAP http://www.w3.org/TR/xmlschema-2/#dateTime

Definición en la línea 167 del archivo gvHidraTimestamp.php.

                                     {
                return $this->format(DateTime::W3C);
        }
formatUser ( )

METODOS PROPIOS DE gvHIDRA Formatea la fecha en el formato User

Definición en la línea 146 del archivo gvHidraTimestamp.php.

                                     {
                $fmt = ConfigFramework::getDateMaskUser();
                //$fmt = $this->outputFormat($fmt);
                $fhora = $this->format('His')!='000000'? ' '.ConfigFramework::getTimeMask(): '';
                return $this->format($fmt.$fhora);
        }
getTimestamp ( )

Devuelve el valor de la fecha en timestamp REVIEW: Hay que revisar este metodo. Cuando utilicemos la version 5.3 de PHP podemos eliminarlo

Definición en la línea 175 del archivo gvHidraTimestamp.php.

                                       {
                // no puedo usar parent en method_exists, luego obtengo instancia del padre
                if (method_exists(new DateTime(), 'getTimestamp'))
                        return parent::getTimestamp();
                $dateFormated = $this->formatFW();
                return strtotime($dateFormated); 
        }
init ( ) [private]

actualiza las propiedades internas cada vez que cambia la fecha

Definición en la línea 133 del archivo gvHidraTimestamp.php.

                                {
                $this->_year = (int) $this->format('Y');
                $this->_month = (int) $this->format('n');
                $this->_day = (int) $this->format('j');         
        } 
isLeap ( )

Indica si el ao es bisiesto

Definición en la línea 378 del archivo gvHidraTimestamp.php.

                                 {
                if ($this->_year % 400 == 0 || ($this->_year % 4 == 0 && $this->_year % 100 != 0)) {
                        return true;
                } else {
                        return false;
                }
        }
modify ( str)

Definición en la línea 125 del archivo gvHidraTimestamp.php.

                                     {
                parent::modify($str);
                $this->init();
        }
static outputFormat ( fmt) [static]

Modifica un formato para que ste siempre tenga ceros en meses y dias menores de 10 De momento no se usa, para no alterar el formato definido en cada nivel

Definición en la línea 225 del archivo gvHidraTimestamp.php.

                                           {
                $fmt = str_replace('j', 'd', $fmt);
                return str_replace('n', 'm', $fmt);
        }
setDate ( year,
month,
day 
)

Sobrecarga del mtodo setDate, para que no permita meses y dias fuera de rango En caso de necesitar, se puede usar el mtodo modify (ej. +1000 days, ...)

Definición en la línea 112 del archivo gvHidraTimestamp.php.

                                                     {
                if (!is_numeric($year) || !is_numeric($month) || !is_numeric($day)) {
                        throw new Exception('setDate() espera tres nmeros separados por comas en el orden: ao, mes, dia');
                }
                if (!checkdate($month, $day, $year)) {
                        throw new Exception('Fecha incorrecta');
                }
                parent::setDate($year, $month, $day);
                $this->_year = (int) $year;
                $this->_month = (int) $month;
                $this->_day = (int) $day;
        }
setTime ( hours,
minutes,
seconds = 0 
)

Sobrecarga del mtodo setTime, para que no permita horas, minutos y segundos fuera del rango En caso de necesitar, se puede usar el metodo modify (ej. +300 seconds, ...)

Definición en la línea 88 del archivo gvHidraTimestamp.php.

                                                                {
                if (!is_numeric($hours) || !is_numeric($minutes) || !is_numeric($seconds)) {
                        throw new Exception('setTime() espera dos o tres nmeros separados por comas en el orden: horas, minutos, segundos');
                }
                $outOfRange = false;
                if ($hours < 0 || $hours > 23) {
                        $outOfRange = true;
                }
                if ($minutes < 0 || $minutes > 59) {
                        $outOfRange = true;
                }
                if ($seconds < 0 || $seconds > 59) {
                        $outOfRange = true;
                }
                if ($outOfRange) {
                        throw new Exception('Hora incorrecta');
                }
                parent::setTime($hours, $minutes, $seconds);
        }
subDays ( numDays)

Definición en la línea 241 del archivo gvHidraTimestamp.php.

                                          {
                if (!is_numeric($numDays)) {
                        throw new Exception('subDays() espera un entero');
                }
                $this->modify('-' . abs(intval($numDays)) . ' days');
        }
subMonths ( numMonths)

Ver comentarios en addMonths

Definición en la línea 304 del archivo gvHidraTimestamp.php.

                                              {
                if (!is_numeric($numMonths)) {
                        throw new Exception('addMonths() espera un entero');
                }
                $numMonths = abs(intval($numMonths));
                // Subtract the months from the current month number.
                $newValue = $this->_month - $numMonths;
                // If the result is greater than 0, it's still the same year,
                // and you can assign the new value to the month.
                if ($newValue > 0) {
                        $this->_month = $newValue;
                } else {
                        // Create an array of the months in reverse.
                        $months = range(12 , 1);
                        // Get the absolute value of $newValue.
                        $newValue = abs($newValue);
                        // Get the array position of the resulting month.
                        $monthPosition = $newValue % 12;
                        $this->_month = $months[$monthPosition];
                        // Arrays begin at 0, so if $monthPosition is 0,
                        // it must be December.
                        if ($monthPosition) {
                                $this->_year -= ceil($newValue / 12);
                        } else {
                                $this->_year -= ceil($newValue / 12) + 1;
                        }
                }
                $this->checkLastDayOfMonth();
                parent::setDate($this->_year, $this->_month, $this->_day);
        }
subWeeks ( numWeeks)

Definición en la línea 255 del archivo gvHidraTimestamp.php.

                                            {
                if (!is_numeric($numWeeks)) {
                        throw new Exception('subWeeks() espera un entero');
                }
                $this->modify('-' . abs(intval($numWeeks)) . ' weeks');
        }
subYears ( numYears)

Ver comentarios en addMonths

Definición en la línea 350 del archivo gvHidraTimestamp.php.

                                            {
                if (!is_numeric($numYears)) {
                        throw new Exception('subYears() espera un entero');
                }
                $this->_year -= abs(intval($numYears));
                $this->checkLastDayOfMonth();
                parent::setDate($this->_year, $this->_month, $this->_day);
        }

Documentación de los campos

$_date_time [private]

Definición en la línea 48 del archivo gvHidraTimestamp.php.

$_day [protected]

Definición en la línea 47 del archivo gvHidraTimestamp.php.

$_month [protected]

Definición en la línea 46 del archivo gvHidraTimestamp.php.

$_year [protected]

Definición en la línea 45 del archivo gvHidraTimestamp.php.


La documentación para esta clase fue generada a partir del siguiente fichero: