fix: timecode conversion of all zeroes or empty strings
This commit is contained in:
parent
82381276b2
commit
34d631e93a
1 changed files with 20 additions and 4 deletions
|
@ -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 -}}
|
||||
|
|
Loading…
Reference in a new issue