diff --git a/lib/Subtitle/BASE.pm b/lib/Subtitle/BASE.pm index ca129b4..838137c 100644 --- a/lib/Subtitle/BASE.pm +++ b/lib/Subtitle/BASE.pm @@ -61,6 +61,20 @@ sub parse_timing { return $time; } +sub build_timing { + my ($self, $time, $prec) = @_; + $prec //= 2; + my ($hrs, $min, $sec, $msec, $rest); + $hrs = int($time / 3600); + $rest = $time - ($hrs * 3600); + $min = int($rest / 60); + $rest = $rest - ($min * 60); + $sec = int($rest / 1); + $msec = sprintf "%.${prec}f", ($rest - ($sec * 1)); + $msec =~ s/^0\.//o; + return sprintf("%d:%02d:%02d.%s", $hrs, $min, $sec, $msec); +} + sub trim { my ($self, $line) = @_; return unless defined $line;