* Run CI tests against php 7.4 * Sort composer dependencies * Remove unused Aws S3 php library * Pin simplepie dependency to ^1.5 * Pin getid3 dependency to ^1.9 * Pin composer semver to ^3.2 * Pin php-amqplib to ^2.12 * Drop sentry logging support * Update composer dependencies * Move propel regenerate to Makefile * Regenerate propel files with v1.7.0 * Pin propel orm to ^1.7 * Regenerate propel files with v1.7.2 * fix: generator_version in airtime-conf-production.php * Replace propel/propel1 with jooola/propel1 * Regenerate propel files with v1.7.3-dev * Fix php7.4 compatibility Using php-cs-fixer: '@PhpCsFixer' => true, 'concat_space' => ['spacing' => 'one'], 'ordered_class_elements' => false, 'yoda_style' => false, '@PHP74Migration' => true, 'assign_null_coalescing_to_coalesce_equal' => false, 'ternary_to_null_coalescing' => false, 'heredoc_indentation' => false, '@PHP74Migration:risky' => true, 'declare_strict_types' => false, 'void_return' => false, 'use_arrow_functions' => false, * Fix pre-commit
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
class LengthFormatter
|
|
{
|
|
/**
|
|
* @string length
|
|
*/
|
|
private $_length;
|
|
|
|
// @param string $length formatted H:i:s.u (can be > 24 hours)
|
|
public function __construct($length)
|
|
{
|
|
$this->_length = $length;
|
|
}
|
|
|
|
public function format()
|
|
{
|
|
if (!preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}/', $this->_length)) {
|
|
return $this->_length;
|
|
}
|
|
|
|
$pieces = explode(':', $this->_length);
|
|
|
|
$seconds = round($pieces[2], 1);
|
|
$seconds = number_format($seconds, 1);
|
|
[$seconds, $milliStr] = explode('.', $seconds);
|
|
|
|
if (intval($pieces[0]) !== 0) {
|
|
$hours = ltrim($pieces[0], '0');
|
|
}
|
|
|
|
$minutes = $pieces[1];
|
|
//length is less than 1 hour
|
|
if (!isset($hours)) {
|
|
if (intval($minutes) !== 0) {
|
|
$minutes = ltrim($minutes, '0');
|
|
}
|
|
//length is less than 1 minute
|
|
else {
|
|
unset($minutes);
|
|
}
|
|
}
|
|
|
|
if (isset($hours, $minutes, $seconds)) {
|
|
$time = sprintf('%d:%02d:%02d.%s', $hours, $minutes, $seconds, $milliStr);
|
|
} elseif (isset($minutes, $seconds)) {
|
|
$time = sprintf('%d:%02d.%s', $minutes, $seconds, $milliStr);
|
|
} else {
|
|
$time = sprintf('%d.%s', $seconds, $milliStr);
|
|
}
|
|
|
|
return $time;
|
|
}
|
|
}
|