From 7b5373315b482c517266970b21e7a75415ba2369 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 17 Mar 2015 14:41:56 +1000 Subject: [PATCH] * Subtitle::BASE->build_timing --- lib/Subtitle/BASE.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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;