/**
* Classe com metodos que tratam de diferencas entre datas
* @author Nelson Costa - nelson.nit@gmail.com
*
*/
class FuncaoData {
/**
* Retorna o mktime de uma data no formato YYYYMMDDHHIISS
* @param string $dt
* @return integer Qt de segundos entre 01/01/1970 00:00:00 e a data fornecida
*/
public static function qtSegundoDtHr($dt_hr) {
return mktime(substr($dt_hr,8,2), substr($dt_hr,10,2), substr($dt_hr,12,2), substr($dt_hr,4,2), substr($dt_hr,6,2), substr($dt_hr,0,4));
}
/**
* Calcula a diferenca em segundos entre duas datas no formato YYYYMMDDHHIISS
* @param string $dt_ini
* @param string $dt_fim
* @return integer Qt. de segundos
*/
public static function difSegundoEntreDtHr($dt_ini, $dt_fim) {
return self::qtSegundoDtHr($dt_ini) - self::qtSegundoDtHr($dt_fim);
}
/**
* Soma em uma data YYYYMMDDHHIISS uma certa quantidade de segundos
* @param string $dt_hr YYYYMMDDHHIISS
* @param integer $qt_seg Qt. de segundos a ser somado
* @return string YYYYMMDDHHIISS
*/
public static function somarSegundoEmDtHr($dt_hr, $qt_seg, $formato = 'YmdHis') {
return date($formato, self::qtSegundoDtHr($dt_hr) + $qt_seg);
}
/**
* Retorna um array no formato array(dia, hora, min, seg)
* @param integer $qt_segundo
* @return array array(dia, hora, min, seg)
*/
public static function dtDiaHrMinSeg($qt_segundo) {
$fullDia = floor($qt_segundo/86400);
$fullHora = floor(($qt_segundo - ($fullDia*86400))/3600);
$fullMin = floor(($qt_segundo-($fullDia*86400)-($fullHora*3600))/60);
$fullSeg = $qt_segundo - $fullDia*86400 - $fullHora*3600 - $fullMin*60;
return array($fullDia, $fullHora, $fullMin, $fullSeg);
}
}
Comentários
Postar um comentário