2
0
forked from Wavyzz/dolibarr

Fix: Format duration function was wrong with some TZ.

This commit is contained in:
Laurent Destailleur
2009-11-17 11:25:11 +00:00
parent 3d7900f3e0
commit f26ecda0b0
2 changed files with 11 additions and 14 deletions

View File

@@ -43,7 +43,7 @@ function ConvertTime2Seconds($iHours=0,$iMinutes=0,$iSeconds=0)
* \param format Output format (all: complete display, hour: displays only hours, min: displays only minutes) * \param format Output format (all: complete display, hour: displays only hours, min: displays only minutes)
* \param lengthOfDay Length of day (default 86400 seconds) * \param lengthOfDay Length of day (default 86400 seconds)
* \return sTime Formated text of duration * \return sTime Formated text of duration
* \example 3600 return 1h00, 86400 return 1d, 90000 return 1day 1hour * \example 0 return 0h00, 3600 return 1h00, 86400 return 1d, 90000 return 1day 1hour
* *
*/ */
function ConvertSecondToTime($iSecond,$format='all',$lengthOfDay=86400) function ConvertSecondToTime($iSecond,$format='all',$lengthOfDay=86400)
@@ -54,9 +54,9 @@ function ConvertSecondToTime($iSecond,$format='all',$lengthOfDay=86400)
if ($format == 'all') if ($format == 'all')
{ {
$sDay=0;
if ($iSecond >= $lengthOfDay) if ($iSecond >= $lengthOfDay)
{ {
$sDay=0;
for($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay ) for($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay )
{ {
$sDay++; $sDay++;
@@ -67,21 +67,18 @@ function ConvertSecondToTime($iSecond,$format='all',$lengthOfDay=86400)
} }
$sTime=''; $sTime='';
if ($sDay) $sTime.=$sDay.' '.$dayTranslate.' '; if ($sDay) $sTime.=$sDay.' '.$dayTranslate.' ';
$sHour = date("H",$iSecond); if ($iSecond)
$sMin = date("i",$iSecond);
//print 'x'.$sHour.'-'.$sMin;
if (intval($sHour) || intval($sMin))
{ {
$sTime.= $sHour.$langs->trans('h').$sMin; $sTime.= dol_print_date($iSecond,'hour',true);
} }
} }
else if ($format == 'hour') else if ($format == 'hour')
{ {
$sTime=date("H",$iSecond); $sTime=dol_print_date($iSecond,'%H',true);
} }
else if ($format == 'min') else if ($format == 'min')
{ {
$sTime=date("i",$iSecond); $sTime=dol_print_date($iSecond,'%M',true);
} }
return $sTime; return $sTime;
} }

View File

@@ -413,7 +413,7 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='',$enc
* "%d/%m/%Y %H:%M", * "%d/%m/%Y %H:%M",
* "%d/%m/%Y %H:%M:%S", * "%d/%m/%Y %H:%M:%S",
* "day", "daytext", "dayhour", "dayhourldap", "dayhourtext" * "day", "daytext", "dayhour", "dayhourldap", "dayhourtext"
* \param to_gmt false=output string if for local server TZ users, true=output string is for GMT users * \param to_gmt false=output string is for local server TZ users, true=output string is for GMT users
* \param outputlangs Object lang that contains language for text translation. * \param outputlangs Object lang that contains language for text translation.
* \return string Formated date or '' if time is null * \return string Formated date or '' if time is null
*/ */