Convert duration in seconds (with ms) to readable format.
```php
$result = HumanHelper::duration(100.123);
// $result will be: '00:01:40.123'
```
@param string $duration
@return string
434044
public static function duration ($duration)
		{
			if (is_numeric($duration))
			{
				$negative = ( $duration < 0 );
				if ($negative)
					$duration = -$duration;

				if (strpos($duration, '.') === false)
					list($seconds, $tail) = [ $duration, 0 ];
				else
					list($seconds, $tail) = explode('.', $duration);

				$dt = new \DateTime('@0');
				$dt2 = new \DateTime("@" . $seconds);

				return ( $negative ? '-' : '' ) . $dt->diff($dt2)->format('%H:%I:%S') . '.' . str_pad($tail, 3, '0', STR_PAD_RIGHT);
			}

			return null;
		}
1191682
public static function secToHourFormat(float $seconds) : string
    {
        $t = round($seconds);

        return sprintf('%02d:%02d:%02d', ($t/3600), ($t/60%60), $t%60);
    }
282302
public static function readTime5($time) {
		if (empty($time) || $time=='NULL') return null;
		if (is_numeric($time)) {
			return '00:' . $time;
		} else {
			$temp = explode(':', $time);
			return str_pad(intval($temp[0]), 2, '0', STR_PAD_LEFT) . ':' .str_pad(intval($temp[1]), 2, '0', STR_PAD_LEFT);
		}
	}
1236007
public function longFormat($duration)
	{
		if( isset($duration) ) $this->__construct($duration);
		if( $this->hoursSection >= 1 )
		{
			return sprintf(
				' %s ' . str_plural('hour', $this->hoursSection) .
				' %s ' . str_plural('minute', $this->minutesSection) .
				' %s ' . str_plural('second', $this->secondsSection)
				, $this->hoursSection, $this->minutesSection, $this->secondsSection);
		}
		if( $this->minutesSection >= 1 && $this->secondsSection )
		{
			return sprintf(
				' %s ' . str_plural('minute', $this->minutesSection) .
				' %s ' . str_plural('second', $this->secondsSection)
				, $this->minutesSection, $this->secondsSection);
		}
		if( $this->minutesSection >= 1 )
		{
			return sprintf(
				' %s ' . str_plural('minute', $this->minutesSection)
				, $this->minutesSection);
		}


		return sprintf(' %s ' . str_plural('second', $this->secondsSection), $this->secondsSection);
	}
840846
public function getTodayTotal($duration = null)
    {
        $total = User::getDb()->cache(function ($db) {
            return User::find()->where(['between', 'created_at', DateHelper::todayFirstSecond(), DateHelper::todayLastSecond()])->count();
        }, $duration);
        return $total;
    }
1348921
public static function parseDuration($duration, $asString = false)
    {
        $result = preg_match('/^(?<plusminus>\+|-)?P((?<week>\d+)W)?((?<day>\d+)D)?(T((?<hour>\d+)H)?((?<minute>\d+)M)?((?<second>\d+)S)?)?$/', $duration, $matches);
        if (!$result) {
            throw new InvalidDataException('The supplied iCalendar duration value is incorrect: '.$duration);
        }

        if (!$asString) {
            $invert = false;

            if ('-' === $matches['plusminus']) {
                $invert = true;
            }

            $parts = [
                'week',
                'day',
                'hour',
                'minute',
                'second',
            ];

            foreach ($parts as $part) {
                $matches[$part] = isset($matches[$part]) && $matches[$part] ? (int) $matches[$part] : 0;
            }

            // We need to re-construct the $duration string, because weeks and
            // days are not supported by DateInterval in the same string.
            $duration = 'P';
            $days = $matches['day'];

            if ($matches['week']) {
                $days += $matches['week'] * 7;
            }

            if ($days) {
                $duration .= $days.'D';
            }

            if ($matches['minute'] || $matches['second'] || $matches['hour']) {
                $duration .= 'T';

                if ($matches['hour']) {
                    $duration .= $matches['hour'].'H';
                }

                if ($matches['minute']) {
                    $duration .= $matches['minute'].'M';
                }

                if ($matches['second']) {
                    $duration .= $matches['second'].'S';
                }
            }

            if ('P' === $duration) {
                $duration = 'PT0S';
            }

            $iv = new DateInterval($duration);

            if ($invert) {
                $iv->invert = true;
            }

            return $iv;
        }

        $parts = [
            'week',
            'day',
            'hour',
            'minute',
            'second',
        ];

        $newDur = '';

        foreach ($parts as $part) {
            if (isset($matches[$part]) && $matches[$part]) {
                $newDur .= ' '.$matches[$part].' '.$part.'s';
            }
        }

        $newDur = ('-' === $matches['plusminus'] ? '-' : '+').trim($newDur);

        if ('+' === $newDur) {
            $newDur = '+0 seconds';
        }

        return $newDur;
    }
17548
public static function buildDefaultTime($duration) {
		$minutes = $duration % HOUR;
		$duration = $duration - $minutes;
		$hours = $duration / HOUR;

		$seconds = $minutes % MINUTE;
		return static::pad($hours) . ':' . static::pad($minutes / MINUTE) . ':' . static::pad($seconds / SECOND);
	}
470856
public static function SecondsFromDuration( $arg )
	{
		if ( $arg instanceof Undefined )
			return Undefined::getValue();

		/**
		 * @var DurationValue $duration
		 */
		$duration = $arg;

		return DecimalValue::FromValue( $duration->getSeconds() * ( $duration->getInverted() ? -1 : 1 ) );
	}
941956
protected function getMinutes($duration)
    {
        if ($duration instanceof DateTime) {
            $duration = (time()-$duration->getTimestamp()) / 60;
        }

        return (int) ($duration * 60) > 0 ? $duration : null;
    }
1363921
public static function timetoDuration($time)
    {
        $duration = 'PT';

        $regexp = "/^([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,6})?$/";

        if (preg_match($regexp, $time, $matches)) {
            $duration .= intval($matches[1]) . 'H' . intval($matches[2]) . 'M';
            $duration .= isset($matches[4])
                ? intval($matches[3]) . $matches[4] . 'S'
                : intval($matches[3]) . 'S';
        } else {
            $duration .= '0S';
        }

        return $duration;
    }
704449
private static function secondsToDuration($seconds)
    {
        $seconds = intval($seconds);
        $hours = floor($seconds / 3600);
        $minutes = floor(($seconds / 60) % 60);
        $seconds = $seconds % 60;

        return "${hours}h ${minutes}m {$seconds}s";
    }
1096238
static public function secondToTime($times)
    {
        $result = '00:00:00';

        if ($times > 0) {
            $hour = floor($times/3600);
            $minute = floor(($times-3600 * $hour)/60);
            $second = floor((($times-3600 * $hour) - 60 * $minute) % 60);
            $result = str_pad($hour, 2, "0", STR_PAD_LEFT).':'.str_pad($minute, 2, "0", STR_PAD_LEFT).':'.str_pad($second, 2, "0", STR_PAD_LEFT);
        }

        return $result;
    }
600748
public static function formatDuration($duration, $precision = 3)
    {
        if ($duration < 1) {
            $duration *= 1000;
            $unit = 'ms';
        } else {
            $unit = 's ';
        }

        return self::toPrecision($duration, $precision) . $unit;
    }
574137
private static function stringToSeconds($duration)
    {
        if (isset(self::$suffixes[substr($duration, -1)])) {
            $amount = substr($duration, 0, strlen($duration) - 1);
            $unit = self::$suffixes[substr($duration, -1)];
        } else {
            $unit = 1;
            $amount = $duration;
        }

        if (!is_numeric($amount)) {
            throw new \InvalidArgumentException('Invalid duration: ' . $duration);
        }

        return $unit * $amount;
    }
1204262
function _format_duration( $duration ) {
    if( !isset( $duration['week'] ) &&
        !isset( $duration['day'] )  &&
        !isset( $duration['hour'] ) &&
        !isset( $duration['min'] )  &&
        !isset( $duration['sec'] ))
      return;
    $output = 'P';
    if( isset( $duration['week'] ) && ( 0 < $duration['week'] ))
      $output       .= $duration['week'].'W';
    else {
      if( isset($duration['day'] ) && ( 0 < $duration['day'] ))
        $output     .= $duration['day'].'D';
      if(( isset( $duration['hour']) && ( 0 < $duration['hour'] )) ||
         ( isset( $duration['min'])  && ( 0 < $duration['min'] ))  ||
         ( isset( $duration['sec'])  && ( 0 < $duration['sec'] ))) {
        $output     .= 'T';
        if( 0 < $duration['hour'] ) {
          $output   .= $duration['hour'].'H';
          if( 0 < $duration['min'] ) {
            $output .= $duration['min'].'M';
            if( 0 < $duration['sec'] )
              $output .= $duration['sec'].'S';
          }
          elseif( 0 < $duration['sec'] )
            $output .= '0M'.$duration['sec'].'S';
        }
        elseif( 0 < $duration['min'] ) {
          $output   .= '0H'.$duration['min'].'M';
          if( 0 < $duration['sec'] )
            $output .= $duration['sec'].'S';
        }
        elseif( 0 < $duration['sec'] )
          $output   .= '0H0M'.$duration['sec'].'S';
      }
    }
    return $output;
  }
298475
def format_duration(minutes, human = True):
    """"""

    if isinstance(minutes, dt.timedelta):
        minutes = duration_minutes(minutes)

    if not minutes:
        if human:
            return ""
        else:
            return "00:00"

    if minutes < 0:
        # format_duration did not work for negative values anyway
        # return a warning
        return "NEGATIVE"

    hours = minutes / 60
    minutes = minutes % 60
    formatted_duration = ""

    if human:
        if minutes % 60 == 0:
            # duration in round hours
            formatted_duration += ("%dh") % (hours)
        elif hours == 0:
            # duration less than hour
            formatted_duration += ("%dmin") % (minutes % 60.0)
        else:
            # x hours, y minutes
            formatted_duration += ("%dh %dmin") % (hours, minutes % 60)
    else:
        formatted_duration += "%02d:%02d" % (hours, minutes)


    return formatted_duration
677057
protected function setDuration($duration)
	{
		if ( ! is_numeric($duration))
		{
			throw new \InvalidArgumentException('The duration value must be a float type.');
		}
		
		$this->duration = abs($duration);
		
		return $this;
	}