From 9d6663cf318d4c7ae8b004fc9a746aa8d707fc58 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Mon, 16 Nov 2009 21:55:03 +0000
Subject: [PATCH] Fix: Error in function ConvertSecondTotime

---
 htdocs/fichinter/fiche.php | 12 ++++++++----
 htdocs/lib/date.lib.php    | 24 ++++++++++++++----------
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php
index 0dc1c5a53ea..3b277f9f68a 100644
--- a/htdocs/fichinter/fiche.php
+++ b/htdocs/fichinter/fiche.php
@@ -445,7 +445,7 @@ if ($_GET["action"] == 'create')
 		print '<input type="hidden" name="action" value="add">';
 
 		print '<tr><td>'.$langs->trans("Ref").'</td>';
-		print '<td><input name="ref" value="$numpr"></td></tr>'."\n";
+		print '<td><input name="ref" value="'.$numpr.'"></td></tr>'."\n";
 
 		if ($conf->projet->enabled)
 		{
@@ -488,7 +488,7 @@ if ($_GET["action"] == 'create')
 		print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="GET">';
 		print '<table class="border" width="100%">';
 		print '<tr><td>'.$langs->trans("Company").'</td><td>';
-		$html->select_societes('','socid','s.client = 1',1);
+		$html->select_societes('','socid','',1);
 		print '</td></tr>';
 		print '<tr><td colspan="2" align="center">';
 		print '<input type="hidden" name="action" value="create">';
@@ -550,7 +550,7 @@ elseif ($fichinterid)
 	print $html->showrefnav($fichinter,'ref','',1,'ref','ref');
 	print '</td></tr>';
 
-	// Societe
+	// Third party
 	print "<tr><td>".$langs->trans("Company")."</td><td>".$fichinter->client->getNomUrl(1)."</td></tr>";
 
 	// Project
@@ -584,7 +584,11 @@ elseif ($fichinterid)
 	}
 
 	// Duration
-	print '<tr><td>'.$langs->trans("TotalDuration").'</td><td>'.ConvertSecondToTime($fichinter->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY).'</td></tr>';
+	print '<tr><td>'.$langs->trans("TotalDuration").'</td>';
+	//print $fichinter->duree.'-'.$conf->global->MAIN_DURATION_OF_WORKDAY;
+	print '<td>'.ConvertSecondToTime($fichinter->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
+	//print '<td>'.ConvertSecondToTime(90000,'all',$conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
+	print '</tr>';
 
 	// Description (must be a textarea and not html must be allowed (used in list view)
 	print '<tr><td>';
diff --git a/htdocs/lib/date.lib.php b/htdocs/lib/date.lib.php
index a621d539872..060690f3f9d 100644
--- a/htdocs/lib/date.lib.php
+++ b/htdocs/lib/date.lib.php
@@ -38,11 +38,13 @@ function ConvertTime2Seconds($iHours=0,$iMinutes=0,$iSeconds=0)
 }
 
 
-/**	  \brief      Return, in clear text, value of a number of seconds in days, hours and minutes
- *    \param      iSecond		Number of seconds
- *    \param      format		Output format (all: complete display, hour: displays only hours, min: displays only minutes)
- *    \param      lengthOfDay	Length of day (default 86400 seconds)
- *    \return     sTime			Formated text of duration
+/**	  	\brief      Return, in clear text, value of a number of seconds in days, hours and minutes
+ *    	\param      iSecond		Number of seconds
+ *    	\param      format		Output format (all: complete display, hour: displays only hours, min: displays only minutes)
+ *    	\param      lengthOfDay	Length of day (default 86400 seconds)
+ *    	\return     sTime			Formated text of duration
+ * 		\example	3600 return 1h00, 86400 return 1d, 90000 return 1day 1hour
+ * 					
  */
 function ConvertSecondToTime($iSecond,$format='all',$lengthOfDay=86400)
 {
@@ -55,25 +57,27 @@ function ConvertSecondToTime($iSecond,$format='all',$lengthOfDay=86400)
 		if ($iSecond >= $lengthOfDay)
 		{
 			$sDay=0;
-			for( $i = $iSecond; $i > $lengthOfDay; $i -= $lengthOfDay )
+			for( $i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay )
 			{
 				$sDay++;
+				$iSecond-=$lengthOfDay;
 			}
 			$dayTranslate = $langs->trans("Day");
 			if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days");
 		}
 		$sTime='';
 		if ($sDay) $sTime.=$sDay.' '.$dayTranslate.' ';
-		$sHour = date("H",$iSecond)-1;
+		$sHour = date("H",$iSecond);
 		$sMin  = date("i",$iSecond);
-		if (!empty($sHour) && !empty($sMin))
+		//print 'x'.$sHour.'-'.$sMin;
+		if (intval($sHour) || intval($sMin))
 		{
-			$sTime.= $sHour.'h'.$sMin;
+			$sTime.= $sHour.$langs->trans('h').$sMin;
 		}
 	}
 	else if ($format == 'hour')
 	{
-		$sTime=date("H",$iSecond)-1;
+		$sTime=date("H",$iSecond);
 	}
 	else if ($format == 'min')
 	{
-- 
GitLab