mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
working on dimed balances
This commit is contained in:
@@ -31,7 +31,7 @@ type MinuteBucket struct {
|
||||
Price float64
|
||||
Percent float64 // percentage from standard price
|
||||
DestinationIds []string
|
||||
ExpirationTime time.Time
|
||||
ExpirationDate time.Time
|
||||
precision int
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ Splits the given timespan on minute bucket's duration.
|
||||
*/
|
||||
func (ts *TimeSpan) SplitByMinuteBucket(mb *MinuteBucket) (newTs *TimeSpan) {
|
||||
// if mb expired skip it
|
||||
if ts.TimeStart.Equal(mb.ExpirationTime) || ts.TimeStart.After(mb.ExpirationTime) {
|
||||
if !mb.ExpirationTime.IsZero() && (ts.TimeStart.Equal(mb.ExpirationTime) || ts.TimeStart.After(mb.ExpirationTime)) {
|
||||
return nil
|
||||
}
|
||||
s := ts.GetDuration().Seconds()
|
||||
|
||||
@@ -217,3 +217,45 @@ func TestSetInterval(t *testing.T) {
|
||||
t.Error("Bigger ponder interval should win")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimespanSplitByMinuteBucketPlenty(t *testing.T) {
|
||||
t1 := time.Date(2013, time.July, 15, 10, 40, 0, 0, time.UTC)
|
||||
t2 := time.Date(2013, time.July, 15, 10, 42, 0, 0, time.UTC)
|
||||
mb := &MinuteBucket{Seconds: 180}
|
||||
ts := TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
newTs := ts.SplitByMinuteBucket(mb)
|
||||
if ts.MinuteInfo == nil || ts.MinuteInfo.Quantity != 120 {
|
||||
t.Error("Not enough minutes on minute bucket split")
|
||||
}
|
||||
if newTs != nil {
|
||||
t.Error("Bad extra timespan on minute bucket split")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimespanSplitByMinuteBucketScarce(t *testing.T) {
|
||||
t1 := time.Date(2013, time.July, 15, 10, 40, 0, 0, time.UTC)
|
||||
t2 := time.Date(2013, time.July, 15, 10, 42, 0, 0, time.UTC)
|
||||
mb := &MinuteBucket{Seconds: 60}
|
||||
ts := TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
newTs := ts.SplitByMinuteBucket(mb)
|
||||
if ts.MinuteInfo == nil || ts.MinuteInfo.Quantity != 60 {
|
||||
t.Error("Not enough minutes on minute bucket split")
|
||||
}
|
||||
if newTs == nil || newTs.MinuteInfo != nil {
|
||||
t.Error("Missing extra timespan on minute bucket split")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimespanSplitByMinuteBucketPlantyExpired(t *testing.T) {
|
||||
t1 := time.Date(2013, time.July, 15, 10, 40, 0, 0, time.UTC)
|
||||
t2 := time.Date(2013, time.July, 15, 10, 42, 0, 0, time.UTC)
|
||||
mb := &MinuteBucket{Seconds: 180, ExpirationDate: time.Date(2013, time.July, 15, 10, 40, 0, 0, time.UTC)}
|
||||
ts := TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
newTs := ts.SplitByMinuteBucket(mb)
|
||||
if ts.MinuteInfo == nil || ts.MinuteInfo.Quantity != 120 {
|
||||
t.Error("Not enough minutes on minute bucket split")
|
||||
}
|
||||
if newTs != nil {
|
||||
t.Error("Bad extra timespan on minute bucket split")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user