From 1691e4ef5e0cca815683962995a5ed7d6621dff2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 29 Oct 2009 08:57:05 +0000 Subject: [PATCH] Add possibility to defined duration of a workday (MAIN_DURATION_OF_WORKDAY) --- htdocs/fichinter/fiche.php | 2 +- htdocs/lib/date.lib.php | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index f70759a8624..0dc1c5a53ea 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -584,7 +584,7 @@ elseif ($fichinterid) } // Duration - print ''.$langs->trans("TotalDuration").''.ConvertSecondToTime($fichinter->duree).''; + print ''.$langs->trans("TotalDuration").''.ConvertSecondToTime($fichinter->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY).''; // Description (must be a textarea and not html must be allowed (used in list view) print ''; diff --git a/htdocs/lib/date.lib.php b/htdocs/lib/date.lib.php index 29b156c47ae..a621d539872 100644 --- a/htdocs/lib/date.lib.php +++ b/htdocs/lib/date.lib.php @@ -39,21 +39,28 @@ 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:affichage complet, hour: n'affiche que les heures, min: n'affiche que les minutes) - * \return sTime Formated text of duration + * \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 */ -function ConvertSecondToTime($iSecond,$format='all') +function ConvertSecondToTime($iSecond,$format='all',$lengthOfDay=86400) { global $langs; + + if (empty($lengthOfDay)) $lengthOfDay = 86400; if ($format == 'all') { - if ($iSecond >= 86400) + if ($iSecond >= $lengthOfDay) { - $sDay=date("d",$iSecond)-1; + $sDay=0; + for( $i = $iSecond; $i > $lengthOfDay; $i -= $lengthOfDay ) + { + $sDay++; + } $dayTranslate = $langs->trans("Day"); - if ($iSecond >= 172800) $dayTranslate = $langs->trans("Days"); + if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days"); } $sTime=''; if ($sDay) $sTime.=$sDay.' '.$dayTranslate.' ';