Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file modifier.display_duration.php

Documentation is available at modifier.display_duration.php

  1. <?php
  2. /**
  3.  * @package Smarty
  4.  * @subpackage plugins
  5.  */
  6.  
  7. /**
  8.  * basic function to convert a number of seconds into a human readable format
  9.  * 
  10.  * @param array $pDuration Duration of event in seconds
  11.  * @access public
  12.  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  13.  */
  14. function smarty_modifier_display_duration( $pDuration ) {
  15.     $units = array(
  16.         'month'  => 60 * 60 * 24 * 7 * 4,
  17.         'week'   => 60 * 60 * 24 * 7,
  18.         'day'    => 60 * 60 * 24,
  19.         'hour'   => 60 * 60,
  20.         'min'    => 60,
  21.         'sec'    => 1,
  22.     );
  23.  
  24.     foreach( $units as $unit => $secs ) {
  25.         $duration[$unit] = 0;
  26.         if( $pDuration > $secs ) {
  27.             $duration[$unit] = floor( $pDuration / $secs );
  28.             $pDuration = $pDuration % $secs;
  29.         }
  30.     }
  31.  
  32.     $ret  = !empty( $duration['month'] ) ? $duration['month'].tra( 'month(s)' ).' ' : '';
  33.     $ret .= !empty( $duration['week'] )  ? $duration['week'] .tra( 'week(s)' ).' '  : '';
  34.     $ret .= !empty( $duration['day'] )   ? $duration['day']  .tra( 'day(s)' ).' '   : '';
  35.     $ret .= str_pad( $duration['hour'], 2, 0, STR_PAD_LEFT ).':'.str_pad( $duration['min'], 2, 0, STR_PAD_LEFT ).':'.str_pad( $duration['sec'], 2, 0, STR_PAD_LEFT );
  36.     return $ret;
  37. }
  38. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:09 +0000 by phpDocumentor 1.5.0-lsces