DRY duration parsing

This commit is contained in:
Sam Lewis
2022-10-31 01:36:40 -04:00
parent ce6649dd29
commit d077c3feec
5 changed files with 18 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
package internal
import (
"fmt"
"log"
"time"
@@ -21,3 +22,11 @@ func ParseTime(s string) carbon.Carbon {
}
return carbon.Now().StartOfDay().SetHour(t.Hour()).SetMinute(t.Minute())
}
func ParseDuration(s string) time.Duration {
d, err := time.ParseDuration(s)
if err != nil {
panic(fmt.Sprintf("Couldn't parse string duration: \"%s\" see https://pkg.go.dev/time#ParseDuration for valid time units", s))
}
return d
}