From 94470e68f3abff382927bcba5ce5e1cd743ddd8d Mon Sep 17 00:00:00 2001 From: Elias Rodrigues Date: Sat, 25 Jul 2020 23:00:27 -0300 Subject: [PATCH] Add function asIntFromTimeDuration() --- util.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/util.go b/util.go index 0d3a181..cb7f0ee 100644 --- a/util.go +++ b/util.go @@ -4,6 +4,7 @@ import ( "reflect" "strconv" "strings" + "time" ) // extractTypeInternal gets the actual underlying type of field value. @@ -229,6 +230,15 @@ func asInt(param string) int64 { return i } +// asIntFromTimeDuration parses param as time.Duration and returns it as int64 +// or panics on error. +func asIntFromTimeDuration(param string) int64 { + d, err := time.ParseDuration(param) + panicIf(err) + + return int64(d) +} + // asUint returns the parameter as a uint64 // or panics if it can't convert func asUint(param string) uint64 {