diff --git a/layouts/partials/timecode_to_ms.tmpl b/layouts/partials/timecode_to_ms.tmpl index a51a34c..e83371e 100644 --- a/layouts/partials/timecode_to_ms.tmpl +++ b/layouts/partials/timecode_to_ms.tmpl @@ -3,11 +3,27 @@ {{- if ne (len $parts) 3 -}} {{- errorf "invalid timestamp %q" . -}} {{- else -}} - {{- $hours := collections.Index $parts 0 | cast.ToInt -}} - {{- $minutes := collections.Index $parts 1 | cast.ToInt -}} + {{- $hoursStr:= collections.Index $parts 0 | strings.TrimLeft "0" -}} + {{- $hours := 0 -}} + {{- with $hoursStr -}} + {{- $hours = cast.ToInt . -}} + {{- end -}} + {{- $minutesStr := collections.Index $parts 1 | strings.TrimLeft "0" -}}$ + {{- $minutes := 0 -}} + {{- with $minutesStr }} + {{- $minutes = cast.ToInt . -}} + {{- end -}} {{- $parts2 := strings.Split (collections.Index $parts 2) "," -}} - {{- $seconds := collections.Index $parts2 0 | cast.ToInt -}} - {{- $milliseconds := collections.Index $parts2 1 | cast.ToInt -}} + {{- $secondsStr := collections.Index $parts2 0 | strings.TrimLeft "0" -}} + {{- $seconds := 0 -}} + {{- with $secondsStr -}} + {{- $seconds = cast.ToInt . -}} + {{- end -}} + {{- $millisecondsStr := collections.Index $parts2 1 | strings.TrimLeft "0" -}} + {{- $milliseconds := 0 -}} + {{- with $millisecondsStr -}} + {{- $milliseconds = cast.ToInt . -}} + {{- end -}} {{- $retvalue = math.Add $retvalue (math.Mul $hours 3600 1000) (math.Mul $minutes 60 1000) (math.Mul $seconds 1000) $milliseconds -}} {{- end -}} {{- return $retvalue -}}