mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 15:48:44 +05:00
ParseZeroRatingSubject adding time unit if missing, fixes #840
This commit is contained in:
@@ -329,6 +329,9 @@ func ParseZeroRatingSubject(tor, rateSubj string) (time.Duration, error) {
|
||||
return 0, errors.New("malformed rating subject: " + rateSubj)
|
||||
}
|
||||
durStr := rateSubj[len(ZERO_RATING_SUBJECT_PREFIX):]
|
||||
if _, err := strconv.ParseFloat(durStr, 64); err == nil { // No time unit, postpend
|
||||
durStr += "ns"
|
||||
}
|
||||
return time.ParseDuration(durStr)
|
||||
}
|
||||
|
||||
|
||||
@@ -413,8 +413,9 @@ func TestMinDuration(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseZeroRatingSubject(t *testing.T) {
|
||||
subj := []string{"", "*zero1s", "*zero5m", "*zero10h"}
|
||||
dur := []time.Duration{time.Second, time.Second, 5 * time.Minute, 10 * time.Hour}
|
||||
subj := []string{"", "*zero1024", "*zero1s", "*zero5m", "*zero10h"}
|
||||
dur := []time.Duration{time.Second, time.Duration(1024),
|
||||
time.Second, 5 * time.Minute, 10 * time.Hour}
|
||||
for i, s := range subj {
|
||||
if d, err := ParseZeroRatingSubject(VOICE, s); err != nil || d != dur[i] {
|
||||
t.Error("Error parsing rating subject: ", s, d, err)
|
||||
|
||||
Reference in New Issue
Block a user