TraktorNmlUtils/utils.go
2024-10-11 15:25:16 +02:00

34 lines
679 B
Go

package main
import (
"errors"
"math"
"strconv"
"strings"
)
// DurationStrToMilliseconds converts a duration string (HH:MM:SS) to milliseconds for Cue points.
func DurationStrToMilliseconds(durationStr string) (float64, error) {
parts := strings.Split(durationStr, ":")
if len(parts) != 3 {
return 0, errors.New("invalid duration string format")
}
hours, err := strconv.Atoi(parts[0])
if err != nil {
return 0, err
}
minutes, err := strconv.Atoi(parts[1])
if err != nil {
return 0, err
}
seconds, err := strconv.ParseFloat(parts[2], 64)
if err != nil {
return 0, err
}
return float64((hours*3600+minutes*60)+int(math.Round(seconds))) * 1000, nil
}