@@ -0,0 +1,21 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user