valera/internal/pause/pause.go

22 lines
360 B
Go
Raw Normal View History

2023-04-05 18:18:25 +00:00
package pause
import (
"strconv"
"strings"
"time"
)
func GetDuration(text string) (time.Duration, error) {
d := strings.TrimSuffix(text, "ч")
d = strings.TrimSuffix(d, "д")
count, err := strconv.Atoi(d)
if err != nil {
return 0, err
}
res := time.Duration(count) * time.Hour
if strings.HasSuffix(text, "д") {
res *= 24
}
return res, nil
}