mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
GetMaxSessionDuration fix
should return no more than initial call descriptor duration
This commit is contained in:
@@ -187,3 +187,11 @@ func ParseDurationWithSecs(durStr string) (time.Duration, error) {
|
||||
func BalanceKey(tenant, account, direction string) string {
|
||||
return fmt.Sprintf("%s:%s:%s", direction, tenant, account)
|
||||
}
|
||||
|
||||
// returns the minimum duration between the two
|
||||
func MinDuration(d1, d2 time.Duration) time.Duration {
|
||||
if d1 < d2 {
|
||||
return d1
|
||||
}
|
||||
return d2
|
||||
}
|
||||
|
||||
@@ -336,3 +336,13 @@ func TestParseDurationWithSecs(t *testing.T) {
|
||||
t.Error("Parsed different than expected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinDuration(t *testing.T) {
|
||||
d1, _ := time.ParseDuration("1m")
|
||||
d2, _ := time.ParseDuration("59s")
|
||||
minD1 := MinDuration(d1, d2)
|
||||
minD2 := MinDuration(d2, d1)
|
||||
if minD1 != d2 || minD2 != d2 {
|
||||
t.Error("Error getting min duration: ", minD1, minD2)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user