From 48684f91aa7fde72a7b1704caf53c8585569c8ec Mon Sep 17 00:00:00 2001 From: Elias Rodrigues Date: Sat, 25 Jul 2020 23:02:42 -0300 Subject: [PATCH] Add baked-in support for time.Duration --- baked_in.go | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/baked_in.go b/baked_in.go index 36e8057..caae8a7 100644 --- a/baked_in.go +++ b/baked_in.go @@ -1129,7 +1129,13 @@ func isEq(fl FieldLevel) bool { return int64(field.Len()) == p case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - p := asInt(param) + var p int64 + + if field.Type() == timeDurationType { + p = asIntFromTimeDuration(param) + } else { + p = asInt(param) + } return field.Int() == p @@ -1541,7 +1547,13 @@ func isGte(fl FieldLevel) bool { return int64(field.Len()) >= p case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - p := asInt(param) + var p int64 + + if field.Type() == timeDurationType { + p = asIntFromTimeDuration(param) + } else { + p = asInt(param) + } return field.Int() >= p @@ -1588,7 +1600,13 @@ func isGt(fl FieldLevel) bool { return int64(field.Len()) > p case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - p := asInt(param) + var p int64 + + if field.Type() == timeDurationType { + p = asIntFromTimeDuration(param) + } else { + p = asInt(param) + } return field.Int() > p @@ -1631,7 +1649,13 @@ func hasLengthOf(fl FieldLevel) bool { return int64(field.Len()) == p case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - p := asInt(param) + var p int64 + + if field.Type() == timeDurationType { + p = asIntFromTimeDuration(param) + } else { + p = asInt(param) + } return field.Int() == p @@ -1767,7 +1791,13 @@ func isLte(fl FieldLevel) bool { return int64(field.Len()) <= p case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - p := asInt(param) + var p int64 + + if field.Type() == timeDurationType { + p = asIntFromTimeDuration(param) + } else { + p = asInt(param) + } return field.Int() <= p @@ -1814,7 +1844,13 @@ func isLt(fl FieldLevel) bool { return int64(field.Len()) < p case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - p := asInt(param) + var p int64 + + if field.Type() == timeDurationType { + p = asIntFromTimeDuration(param) + } else { + p = asInt(param) + } return field.Int() < p