CC-3351 : Track length should only show to tenths of a second in the library
created a length formatter to use in multiple places.
This commit is contained in:
parent
28bb97acfa
commit
19d13889af
14 changed files with 129 additions and 438 deletions
|
@ -0,0 +1,56 @@
|
|||
<?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() {
|
||||
|
||||
$pieces = explode(":", $this->_length);
|
||||
|
||||
$seconds = round($pieces[2], 1);
|
||||
$seconds = number_format($seconds, 1);
|
||||
list($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) && isset($minutes) && isset($seconds)) {
|
||||
$time = sprintf("%d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr);
|
||||
}
|
||||
else if (isset($minutes) && isset($seconds)) {
|
||||
$time = sprintf("%d:%02d.%s", $minutes, $seconds, $milliStr);
|
||||
}
|
||||
else {
|
||||
$time = sprintf("%d.%s", $seconds, $milliStr);
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue