mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
Put time.Time before time.Duration
This commit is contained in:
committed by
Dan Christian Bogos
parent
501cbbc73a
commit
21707a5119
@@ -71,14 +71,14 @@ func StringToInterface(s string) interface{} {
|
||||
if f, err := strconv.ParseFloat(s, 64); err == nil {
|
||||
return f
|
||||
}
|
||||
// time.Duration
|
||||
if d, err := time.ParseDuration(s); err == nil {
|
||||
return d
|
||||
}
|
||||
// time.Time
|
||||
if t, err := ParseTimeDetectLayout(s, "Local"); err == nil {
|
||||
return t
|
||||
}
|
||||
// time.Duration
|
||||
if d, err := time.ParseDuration(s); err == nil {
|
||||
return d
|
||||
}
|
||||
// string
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -215,6 +215,12 @@ func TestStringToInterface(t *testing.T) {
|
||||
if res := StringToInterface("45s"); res != time.Duration(45*time.Second) {
|
||||
t.Error("not parsing time.Duration")
|
||||
}
|
||||
res := StringToInterface("+24h")
|
||||
resTime := res.(time.Time)
|
||||
now := time.Now()
|
||||
if resTime.Hour() != now.Hour() && resTime.Minute() != now.Minute() {
|
||||
t.Error("not parsing time.Time")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastFieldIfToString(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user