Add int64 and float64 type coercion in ToDuration
diff --git a/cast_test.go b/cast_test.go
index f9a24df..2c4e421 100644
--- a/cast_test.go
+++ b/cast_test.go
@@ -6,9 +6,9 @@
package cast
import (
- "testing"
-
"html/template"
+ "testing"
+ "time"
"github.com/stretchr/testify/assert"
)
@@ -151,3 +151,12 @@
assert.Equal(t, ToInt(y), 13)
assert.Equal(t, ToInt(z), 13)
}
+
+func TestToDuration(t *testing.T) {
+ a := time.Second * 5
+ ai := int64(a)
+ b := time.Second * 5
+ bf := float64(b)
+ assert.Equal(t, ToDuration(ai), a)
+ assert.Equal(t, ToDuration(bf), b)
+}
diff --git a/caste.go b/caste.go
index b8e6044..5401c0b 100644
--- a/caste.go
+++ b/caste.go
@@ -43,6 +43,12 @@
switch s := i.(type) {
case time.Duration:
return s, nil
+ case int64:
+ d = time.Duration(s)
+ return
+ case float64:
+ d = time.Duration(s)
+ return
case string:
d, err = time.ParseDuration(s)
return