<?PHP
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.6
Copyright (C) 2006  Sylvain FATOME

This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr
****************************************************************************************/

/**********************/
/* Gestion des heures */
/**********************/

// Formate les heures
 
function formateheure($hre)
{
		$heure = "";

		if (($hre <> "") AND ($hre <> "00:00:00"))
			$heure = $hre;
		else
			$heure = "";
			
		return $heure;
}

// Renvoie une heure en nombre de secondes

function heure_sec($hr)
{
	$total_sec = 0;
	
	if ($hr <> "")
	{
		$tab_heure = explode(":",$hr);

		$heures = $tab_heure[0];
		$minutes = $tab_heure[1];
		$secondes = $tab_heure[2];
		
		$total_sec = ($heures*3600)+($minutes*60)+$secondes;
	}
	
	return $total_sec;
}

// Renvoie un nombre de secondes en heure

function sec_heure($se)
{
	$total_se = $se;

	$heure = $se / 3600;
	$heure = floor($heure);
	
	$total_se = $total_se-($heure*3600);
	
	$minute = $total_se / 60;
	$minute = floor($minute);
	
	$seconde = $total_se-($minute*60);
	
	$format = "%'02s";
	$heure = sprintf ($format,$heure);
	$minute = sprintf ($format,$minute);
	$seconde = sprintf ($format,$seconde);
	
	$strheure = $heure.":".$minute.":".$seconde;
	
	return $strheure;
}

// Différence, en secondes, entre 2 heures ($t2 = la plus grande)
 
function diff_time_sec($t1,$t2)
{
	$diff_sec = 0;
	
	if (($t1 <> "") AND ($t2 <> ""))
	{
		$s1 = heure_sec($t1);
		$s2 = heure_sec($t2);
	
		$diff_sec = $s2-$s1;
	}

	return $diff_sec;
}
?>