2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-12-23 22:29:53 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package rss // import "miniflux.app/v2/internal/reader/rss"
|
2019-12-23 22:29:53 +01:00
|
|
|
|
2023-08-12 12:01:15 +02:00
|
|
|
import (
|
2023-10-21 04:39:32 +02:00
|
|
|
"errors"
|
2023-08-12 12:01:15 +02:00
|
|
|
"math"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
2019-12-23 22:29:53 +01:00
|
|
|
|
2023-10-21 04:39:32 +02:00
|
|
|
var ErrInvalidDurationFormat = errors.New("rss: invalid duration format")
|
|
|
|
|
2024-03-14 05:06:28 +01:00
|
|
|
func getDurationInMinutes(rawDuration string) (int, error) {
|
2023-08-12 12:01:15 +02:00
|
|
|
var sumSeconds int
|
|
|
|
|
|
|
|
durationParts := strings.Split(rawDuration, ":")
|
|
|
|
if len(durationParts) > 3 {
|
2023-10-21 04:39:32 +02:00
|
|
|
return 0, ErrInvalidDurationFormat
|
2023-08-12 12:01:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, durationPart := range durationParts {
|
|
|
|
durationPartValue, err := strconv.Atoi(durationPart)
|
|
|
|
if err != nil {
|
2023-10-21 04:39:32 +02:00
|
|
|
return 0, ErrInvalidDurationFormat
|
2023-08-12 12:01:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sumSeconds += int(math.Pow(60, float64(len(durationParts)-i-1))) * durationPartValue
|
|
|
|
}
|
|
|
|
|
|
|
|
return sumSeconds / 60, nil
|
|
|
|
}
|