mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Rermoved case in NewDecimalFromUsage
This commit is contained in:
committed by
Dan Christian Bogos
parent
c1df5d3767
commit
768fcde9f9
@@ -595,17 +595,15 @@ func (ext *APICostIncrement) AsCostIncrement() (cIncr *CostIncrement, err error)
|
||||
cIncr = &CostIncrement{
|
||||
FilterIDs: ext.FilterIDs,
|
||||
}
|
||||
if ext.Increment != EmptyString {
|
||||
if cIncr.Increment, err = NewDecimalFromUsage(ext.Increment); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if ext.FixedFee != nil {
|
||||
cIncr.FixedFee = NewDecimalFromFloat64(*ext.FixedFee)
|
||||
}
|
||||
if ext.RecurrentFee != nil {
|
||||
cIncr.RecurrentFee = NewDecimalFromFloat64(*ext.RecurrentFee)
|
||||
}
|
||||
if ext.Increment != EmptyString {
|
||||
cIncr.Increment, err = NewDecimalFromUsage(ext.Increment)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -110,23 +110,14 @@ func NewDecimalFromUsage(u string) (d *Decimal, err error) {
|
||||
case u == EmptyString:
|
||||
d = NewDecimal(0, 0)
|
||||
//"ns", "us" (or "µs"), "ms", "s", "m", "h"
|
||||
case strings.HasSuffix(u, NsSuffix), strings.HasSuffix(u, UsSuffix), strings.HasSuffix(u, µSuffix), strings.HasSuffix(u, MsSuffix),
|
||||
strings.HasSuffix(u, SSuffix), strings.HasSuffix(u, MSuffix), strings.HasSuffix(u, HSuffix):
|
||||
case strings.HasSuffix(u, SSuffix), strings.HasSuffix(u, MSuffix), strings.HasSuffix(u, HSuffix):
|
||||
var tm time.Duration
|
||||
if tm, err = time.ParseDuration(u); err != nil {
|
||||
return
|
||||
}
|
||||
d = NewDecimal(int64(tm), 0)
|
||||
case strings.Contains(u, NestingSep):
|
||||
if d, err = NewDecimalFromString(u); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
var i int64
|
||||
if i, err = strconv.ParseInt(u, 10, 64); err != nil {
|
||||
return
|
||||
}
|
||||
d = NewDecimal(i, 0)
|
||||
d, err = NewDecimalFromString(u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user