fix: timecode conversion of all zeroes or empty strings

This commit is contained in:
Florian Maury 2024-10-27 15:52:29 +01:00
parent 82381276b2
commit 34d631e93a

View file

@ -3,11 +3,27 @@
{{- if ne (len $parts) 3 -}} {{- if ne (len $parts) 3 -}}
{{- errorf "invalid timestamp %q" . -}} {{- errorf "invalid timestamp %q" . -}}
{{- else -}} {{- else -}}
{{- $hours := collections.Index $parts 0 | cast.ToInt -}} {{- $hoursStr:= collections.Index $parts 0 | strings.TrimLeft "0" -}}
{{- $minutes := collections.Index $parts 1 | cast.ToInt -}} {{- $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) "," -}} {{- $parts2 := strings.Split (collections.Index $parts 2) "," -}}
{{- $seconds := collections.Index $parts2 0 | cast.ToInt -}} {{- $secondsStr := collections.Index $parts2 0 | strings.TrimLeft "0" -}}
{{- $milliseconds := collections.Index $parts2 1 | cast.ToInt -}} {{- $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 -}} {{- $retvalue = math.Add $retvalue (math.Mul $hours 3600 1000) (math.Mul $minutes 60 1000) (math.Mul $seconds 1000) $milliseconds -}}
{{- end -}} {{- end -}}
{{- return $retvalue -}} {{- return $retvalue -}}