Convert seconds to human readable format

@param int $seconds
@return string
191129
protected function _secondsToHuman($seconds) {
		return (new DateTime('today'))->diff(new DateTime('today +' . (int)$seconds . ' seconds'))->format(Configure::read('Task.dateDiffFormat'));
	}
708994
def _format_time(seconds):
    

    # Always do minutes and seconds in mm:ss format
    minutes = seconds // 60
    hours = minutes // 60
    rtn = u'{0:02.0f}:{1:02.0f}'.format(minutes % 60, seconds % 60)

    #  Add hours if there are any
    if hours:

        rtn = u'{0:d}h {1}'.format(int(hours % 24), rtn)

        #  Add days if there are any
        days = int(hours // 24)
        if days:
            rtn = u'{0:d}d {1}'.format(days, rtn)

    return rtn
95508
public function seconds($seconds) {

		if(false === ('-' . intval($seconds) == '-' . $seconds)) {
   			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($seconds)), E_USER_ERROR);
   		}

		$this -> seconds = $seconds;

		return $this;
	}
635302
public function seconds_to_unit($seconds) {
        if ($seconds == 0) {
            return array(0, $this->_options['defaultunit']);
        }
        foreach ($this->get_units() as $unit => $notused) {
            if (fmod($seconds, $unit) == 0) {
                return array($seconds / $unit, $unit);
            }
        }
        return array($seconds, 1);
    }
560231
public function expiresIn( int $seconds ) : Token
	{
		if ( $seconds > 0 )
		{
			$this->expiry = new DateTimeImmutable( sprintf( '+%d seconds', $seconds ) );

			return $this;
		}

		throw (new InvalidExpiryInterval())->withSeconds( $seconds );
	}
1234423
def format_seconds(seconds, hide_seconds=False):
    
    if seconds <= 60:
        return str(seconds)
    output = ""
    for period, period_seconds in (
        ('y', 31557600),
        ('d', 86400),
        ('h', 3600),
        ('m', 60),
        ('s', 1),
    ):
        if seconds >= period_seconds and not (hide_seconds and period == 's'):
            output += str(int(seconds / period_seconds))
            output += period
            output += " "
            seconds = seconds % period_seconds
    return output.strip()
235810
protected function splitDuration($seconds, $max)
    {
        if ($max < 1 || $seconds < 60) {
            return [$seconds];
        }
        
        $minutes = floor($seconds / 60);
        $seconds = $seconds % 60;
        if ($max < 2 || $minutes < 60) {
            return [$seconds, $minutes];
        }
        
        $hours = floor($minutes / 60);
        $minutes = $minutes % 60;
        if ($max < 3 || $hours < 24) {
            return [$seconds, $minutes, $hours];
        }
        
        $days = floor($hours / 24);
        $hours = $hours % 24;
        if ($max < 4 || $days < 7) {
            return [$seconds, $minutes, $hours, $days]; 
        }
        
        $weeks = floor($days / 7);
        $days = $days % 7;
        if ($max < 5 || $weeks < 52) {
            return [$seconds, $minutes, $hours, $days, $weeks];
        }
        
        $years = floor($weeks / 52);
        $weeks = $weeks % 52;
        return [$seconds, $minutes, $hours, $days, $weeks, $years];
    }
378490
public function displayFor(int $seconds)
	{
		$this->options['t'] = $seconds;
		$this->displayFor = $seconds;

		return $this;
	}
68866
public function formatDuration($duration) {
        if ($duration < 1.0e-3) {
            $n = number_format($duration * 1.0e6, 0);
            $sx = 'μs';
        } elseif ($duration < 1) {
            $n = number_format($duration * 1000, 0);
            $sx = 'ms';
        } elseif ($duration < 60) {
            $n = number_format($duration, 1);
            $sx = 's';
        } elseif ($duration < 3600) {
            $n = number_format($duration / 60, 1);
            $sx = 'm';
        } elseif ($duration < 86400) {
            $n = number_format($duration / 3600, 1);
            $sx = 'h';
        } else {
            $n = number_format($duration / 86400, 1);
            $sx = 'd';
        }

        $result = rtrim($n, '0.').$sx;
        return $result;
    }
90081
public static function secondsToPeriod(int $time): string
    {
        $seconds_in_minute = 60;
        $seconds_in_hour = 3600;
        $seconds_in_day = 86400;

        // Timing
        $days = floor($time / $seconds_in_day);
        $time -= ($seconds_in_day * $days);

        $hours = floor($time / $seconds_in_hour);
        $time -= ($seconds_in_hour * $hours);

        $minutes = floor($time / $seconds_in_minute);
        $time -= ($seconds_in_minute * $minutes);

        $seconds = $time;

        // Format
        $out = '';
        if ($days) {
            $out .= $days . ' ';
        }
//        if ($hours) {
        $hours = str_pad($hours, 2, '0', STR_PAD_LEFT);
        $out .= $hours . ':';
//        }
//        if ($minutes) {
        $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
        $out .= $minutes . ':';
//        }
        $seconds = str_pad($seconds, 2, '0', STR_PAD_LEFT);
        $out .= $seconds;

        return $out;
    }
1363747
public function humanize($duration = null)
    {
        if (null !== $duration) {
            $this->parse($duration);
        }

        if ($this->seconds > 0 || ($this->seconds === 0.0 && $this->minutes === 0 && $this->hours === 0 && $this->days === 0)) {
            $this->output .= $this->seconds . 's';
        }

        if ($this->minutes > 0) {
            $this->output = $this->minutes . 'm ' . $this->output;
        }

        if ($this->hours > 0) {
            $this->output = $this->hours . 'h ' . $this->output;
        }

        if ($this->days > 0) {
            $this->output = $this->days . 'd ' . $this->output;
        }

        return trim($this->output());
    }
1331854
public static function secondsToTime($inputSeconds) {
        $secondsInAMinute = 60;
        $secondsInAnHour = 60 * $secondsInAMinute;
        $secondsInADay = 24 * $secondsInAnHour;
        $secondsInAMonth = 30 * $secondsInADay;
        $secondsInAYear = 12 * $secondsInAMonth;

        $years = floor($inputSeconds / $secondsInAYear);

        $monthSeconds = $inputSeconds % $secondsInAYear;
        $months = floor($monthSeconds / $secondsInAMonth);

        $daySeconds = $monthSeconds % $secondsInAMonth;
        $days = floor($daySeconds / $secondsInADay);

        $hourSeconds = $daySeconds % $secondsInADay;
        $hours = floor($hourSeconds / $secondsInAnHour);

        $minuteSeconds = $hourSeconds % $secondsInAnHour;
        $minutes = floor($minuteSeconds / $secondsInAMinute);

        $remainingSeconds = $minuteSeconds % $secondsInAMinute;
        $seconds = ceil($remainingSeconds);

        $aReturn = array(
            'y' => (int) $years,
            'm' => (int) $months,
            'd' => (int) $days,
            'h' => (int) $hours,
            'i' => (int) $minutes,
            's' => (int) $seconds
        );
        return $aReturn;
    }
570974
private function formatDuration($milliseconds)
    {
        $hours = floor($milliseconds / 1000 / 3600);
        $milliseconds -= ($hours * 3600 * 1000);

        $minutes = floor($milliseconds / 1000 / 60);
        $milliseconds -= ($minutes * 60 * 1000);

        $seconds = floor($milliseconds / 1000);
        $milliseconds -= ($seconds * 1000);

        $values = [
            'hour' => $hours,
            'minute' => $minutes,
            'second' => $seconds,
            'millisecond' => $milliseconds,
        ];

        $parts = [];

        foreach ($values as $text => $value) {
            if ($value > 0) {
                $parts[] = $value.' '.$text.($value > 1 ? 's' : '');
            }
        }

        return implode(' ', $parts);
    }
487713
public function getMinutesAsHours($minutes)
    {
        $hours = floor($minutes / 60);
        $minutes = $minutes - ($hours * 60);

        return sprintf('%s:%s', $hours, str_pad($minutes, 2, '0', STR_PAD_LEFT));
    }
1054447
public function format(string $format): string
    {
        return CommonTime::inSeconds($this->seconds)->format($format);
    }
833579
public function getSecondsAsTextExtended($seconds)
    {
        $seconds = floatval($seconds);
        $result = [];

        $steps = [
            'days'    => 86400,
            'hours'   => 3600,
            'minutes' => 60,
            'seconds' => 1,
        ];

        foreach ($steps as $stepName => $stepDivider) {
            $stepCount = floor($seconds / $stepDivider);
            if (0 < $stepCount) {
                $result[] = sprintf('%d %s', $stepCount, $this->getTranslator()->transChoice($stepName, $stepCount));
                $seconds = $seconds - ($stepCount * $stepDivider);
            }
        }

        return implode(' ', $result);
    }
1237362
public static function secondsToTime($seconds)
  {
    $dtF = new DateTime('@0');
    $dtT = new DateTime("@$seconds");
    $res = $dtF->diff($dtT);
    
    $days    = $res->format('%a');
    $hours   = $res->format('%h');
    $minutes = $res->format('%i');
    $seconds = $res->format('%s');
    
    $str = [];
    if ( intval($days) > 0 ){
      $str[] = $days.' '.($days===1?'day':'days');
    }
    if ( intval($hours) > 0 ){
      $str[] = $hours.' '.($hours===1?'hour':'hours');
    }
    if ( intval($minutes) > 0 ){
      $str[] = $minutes.' '.($minutes===1?'minute':'minutes');
    }
    if ( intval($seconds) > 0 ){
      $str[] = $seconds.' '.($seconds===1?'second':'seconds');
    }
    
    return implode(' ', $str);
  }