♻️ Use HoursMinSecondsToS to parse time for fading/trimming

This commit is contained in:
Dan Jones 2023-09-08 15:24:40 -05:00
commit 4057d00c46
3 changed files with 40 additions and 18 deletions

View file

@ -1,6 +1,7 @@
package utils
import (
"errors"
"fmt"
p "path"
"strings"
@ -14,8 +15,11 @@ func GetShortPath(path string) string {
return fmt.Sprintf("%s/%s", dir, base)
}
func HourMinSecToSeconds(time string) float64 {
func HourMinSecToSeconds(time string) (float64, error) {
parts := strings.Split(time, ":")
if len(parts) > 3 {
return 0, errors.New(fmt.Sprintf("Can't parse %s. Must be in HH:MM:SS format", time))
}
units := []string{"h", "m", "s"}
units = units[len(units)-len(parts):]
f := ""
@ -23,5 +27,5 @@ func HourMinSecToSeconds(time string) float64 {
f = f + part + units[idx]
}
dur, _ := t.ParseDuration(f)
return dur.Seconds()
return dur.Seconds(), nil
}