Location: PHPKode > scripts > Web Server Backup > backup/en/cls_fecha_hora.php
<?php
/*********************************************/
/* Class backup                              */
/* ----------------------------------------- */
/* Description: works with dates and hours.  */
/* Author: Eduardo Martos Gómez.             */
/* e-mail: hide@address.com   */
/* License: cite author's name               */
/* Date: 10/03/2004.                         */
/*********************************************/
class fecha_hora
{
	/*************/
	/* Variables */
	/*************/
  var $fecha;					// Date
	var $hora;					// Hour
	var $desfase = 2;		// Time lag
	
	/********************/
	/* Setter functions */
	/********************/
  
	// Sets date
	function set_fecha ($valor)
  {
    $this->fecha = $valor;
  }
	// Sets hour
  function set_hora ($valor)
  {
    $this->hora = $valor;
  }
	// Sets time lag
  function set_desfase ($valor)
  {
    $this->desfase = $valor;
  }

	/*************************************************/
	/* Functions get_dia (), get_mes (), get_anyo () */
	/* --------------------------------------------- */
	/* Returns date in parts.                        */
	/*************************************************/
  function get_dia ($ceros = true)
  {
    $res = substr ($this->fecha, 6, 2);
    if ($ceros == true) $res = $this->ceros ($res, 2, 0);
    return $res;
  }
  function get_mes ($ceros = true)
  {
    $res = substr ($this->fecha, 4, 2);
    if ($ceros == true) $res = $this->ceros ($res, 2, 0);
    return $res;
  }
  function get_anyo ($ceros = true)
  {
    $res = substr ($this->fecha, 0, 4);
    if ($ceros == true) $res = $this->ceros ($res, 4, 0);
    return $res;
  }

	/****************************************/
	/* Functions get_hora (), get_minuto () */
	/* ------------------------------------ */
	/* Returns hour in parts.               */
	/****************************************/
  function get_hora ($ceros = true)
  {
    $res = substr ($this->hora, 0, 2);
    if ($ceros == true) $res = $this->ceros ($res, 2, 0);
    return $res;
  }
  function get_minuto ($ceros = true)
  {
    $res = substr ($this->hora, 2, 2);
    if ($ceros == true) $res = $this->ceros ($res, 2, 0);
    return $res;
  }

	/*************************/
	/* Function fecha ()     */
	/* --------------------- */
	/* Returns current date  */
	/* in dd/mm/yyyy format. */
	/*************************/
  function fecha ()
  {
  	$dia = $this->ceros (trim (gmdate ("j", time() + (3600 * $this->desfase))), 2, 0);
  	$mes = $this->ceros (trim (gmdate ("n", time() + (3600 * $this->desfase))), 2, 0);
  	$anyo = trim (gmdate("Y", time () + (3600 * $this->desfase)));
  	$fecha = $dia.'/'.$mes. '/'. $anyo;
  	return $fecha;	
  }

	/************************/
	/* Function hora ()     */
	/* -------------------- */
	/* Returns current hour */
	/* in hh:mm format.     */
	/************************/
  function hora()
  {
    return gmdate ("H:i", time() + (3600 * $this->desfase));
  }

	/*********************************************/
	/* Function ceros ()                         */
	/* ----------------------------------------- */
	/* Adds $num zeros in the side of $cad       */
	/* specified by $izq_dr (0: left, 1: right). */
	/*********************************************/
  function ceros ($cad, $num, $izq_dr)
  {
  	if ($izq_dr == 0)
      while (strlen ($cad) < $num) $cad = "0".$cad;
    else
      while (strlen ($cad) < $num) $cad .= "0";
  	return $cad;
  }

	/******************************************/
	/* Function fecha_bd ()                   */
	/* -------------------------------------- */
	/* Returns a date in yyyymmdd format.     */
	/* If you don't specify the $f parameter, */
	/* it takes $this->fecha instead.         */
	/******************************************/
  function fecha_bd ($f = "")
  {
    if ($f == "") $f = $this->fecha ();
    $p1 = strpos ($f, "/");
    $p2 = strpos ($f, "/", $p1 + 1);
    $d = substr ($f, 0, $p1);                 // Día
    $m = substr ($f, $p1 + 1, $p2 - $p1 - 1); // Mes
    $a = substr ($f, $p2 + 1);                // Año
    return $a.$m.$d;
  }

	/*********************************************/
	/* Function hora_bd ()                       */
	/* ----------------------------------------- */
	/* Returns an hour in hhmm format.           */
	/* If you don't specify the $hora parameter, */
	/* it takes $this->hora instead.             */
	/*********************************************/
  function hora_bd ($hora = "")
  {
    if ($hora == "") $hora = $this->hora ();
    $p = strpos ($hora, ":");
    $h = substr ($hora, 0, $p);  // Hora
    $m = substr ($hora, $p + 1); // Minuto
    return $h.$m;
  }

	/*****************************************/
	/* Function fecha_ed ()                  */
	/* ------------------------------------- */
	/* Returns $f date in dd/mm/yyyy format. */
	/* $f must have aaaammdd format          */
	/*****************************************/
  function fecha_ed ($f)
  {
    $d = substr ($f, 6);    // Día
    $m = substr ($f, 4, 2); // Mes
    $a = substr ($f, 0, 4); // Año
    $m = intval ($m);
    $m = $this->texto_mes ($m);
    return $d."/".$m."/".$a;
  }

	/***************************************/
	/* Function hora_ed ()                 */
	/* ----------------------------------- */
	/* Returns $hora hour in hh:mm format. */
	/* $hora must have hhmm format.        */
	/***************************************/
  function hora_ed ($hora)
  {
    $hora = $this->ceros ($hora, 4, 0);
    $h = substr ($hora, 0, 2); // Hora
    $m = substr ($hora, 2);    // Minuto
    if ($h == 24) $h = "0";
    return $h.":".$m;
  }

	/***********************************/
	/* Function texto_mes ()           */
	/* ------------------------------- */
	/* Returns the first three letters */
	/* of the month specified by $mes. */
	/***********************************/
  function texto_mes ($mes)
  {
		$arr_meses = split (",", "JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC");
  	return $arr_meses[$mes-1];
  }
}
?>
Return current item: Web Server Backup