diff --git a/timespans/activationperiod.go b/timespans/activationperiod.go index ecca7e133..f3a73975c 100644 --- a/timespans/activationperiod.go +++ b/timespans/activationperiod.go @@ -4,6 +4,7 @@ import ( "strconv" "strings" "time" + //"log" ) /* @@ -61,8 +62,10 @@ func (ap *ActivationPeriod) restore(input string) { i.Month = time.Month(month) i.MonthDay, _ = strconv.Atoi(ise[1]) for _, d := range strings.Split(ise[2], ",") { - wd, _ := strconv.Atoi(d) - i.WeekDays = append(i.WeekDays, time.Weekday(wd)) + if d != ""{ + wd, _ := strconv.Atoi(d) + i.WeekDays = append(i.WeekDays, time.Weekday(wd)) + } } i.StartTime = ise[3] i.EndTime = ise[4] diff --git a/timespans/calldesc.go b/timespans/calldesc.go index ee9c9000f..e20be8248 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -118,7 +118,7 @@ func (cd *CallDescriptor) GetCost(sg StorageGetter) (result *CallCost, err error destPrefix, err := cd.RestoreFromStorage(sg) timespans := cd.splitInTimeSpans() - + cost := 0.0 for _, ts := range timespans { cost += ts.GetCost() diff --git a/timespans/calldesc_test.go b/timespans/calldesc_test.go index e4de5a678..d8893ba54 100644 --- a/timespans/calldesc_test.go +++ b/timespans/calldesc_test.go @@ -126,6 +126,20 @@ func TestLessThanAMinute(t *testing.T) { } } +func TestUniquePrice(t *testing.T) { + getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10) + defer getter.Close() + + t1 := time.Date(2012, time.February, 8, 22, 50, 0, 0, time.UTC) + t2 := time.Date(2012, time.February, 8, 23, 50, 21, 0, time.UTC) + cd := &CallDescriptor{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0723045326", TimeStart: t1, TimeEnd: t2} + result, _ := cd.GetCost(getter) + expected := &CallCost{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0723", Cost: 60.35, ConnectFee: 0} + if *result != *expected { + t.Errorf("Expected %v was %v", expected, result) + } +} + /*********************************** BENCHMARKS ***************************************/ func BenchmarkRedisGetting(b *testing.B) { b.StopTimer() diff --git a/timespans/intervals.go b/timespans/intervals.go index 6495ebc06..f082dbdbc 100644 --- a/timespans/intervals.go +++ b/timespans/intervals.go @@ -4,6 +4,7 @@ import ( "strconv" "strings" "time" + //"log" ) /* diff --git a/timespans/test.kch b/timespans/test.kch index db7902939..cf1a25715 100644 Binary files a/timespans/test.kch and b/timespans/test.kch differ diff --git a/timespans/test_data.json b/timespans/test_data.json index 8216b7545..e19dd784a 100644 --- a/timespans/test_data.json +++ b/timespans/test_data.json @@ -22,5 +22,12 @@ ] } ] +}, +{"TOR": 0,"CstmId":"vdf","Subject":"rif","DestinationPrefix":"0723", "ActivationPeriods": [ + {"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [ + {"BillingUnit":60,"ConnectFee":0,"Month":0,"MonthDay":0,"Ponder":0,"Price":1,"StartTime":"","EndTime":""} + ] + } + ] } ]