Add TimeCode::fromSeconds method
This commit is contained in:
parent
05a8a6c063
commit
3fa1ea1f4f
2 changed files with 48 additions and 0 deletions
|
|
@ -63,4 +63,30 @@ class TimeCode
|
|||
|
||||
return new static($hours, $minutes, $seconds, $frames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates timecode from number of seconds.
|
||||
*
|
||||
* @param float $seconds
|
||||
*
|
||||
* @return TimeCode
|
||||
*/
|
||||
public static function fromSeconds($quantity)
|
||||
{
|
||||
$minutes = $hours = $frames = 0;
|
||||
|
||||
$frames = round(100 * ($quantity - floor($quantity)));
|
||||
$seconds = floor($quantity);
|
||||
|
||||
if ($seconds > 59) {
|
||||
$minutes = floor($seconds / 60);
|
||||
$seconds = $seconds % 60;
|
||||
}
|
||||
if ($minutes > 59) {
|
||||
$hours = floor($minutes / 60);
|
||||
$minutes = $minutes % 60;
|
||||
}
|
||||
|
||||
return new static($hours, $minutes, $seconds, $frames);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue