mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add support for *monthly_estimated fixes #2255
This commit is contained in:
@@ -209,8 +209,16 @@ func ParseTimeDetectLayout(tmStr string, timezone string) (time.Time, error) {
|
||||
return time.Now().AddDate(0, 0, 1), nil // add one day
|
||||
case tmStr == "*monthly":
|
||||
return time.Now().AddDate(0, 1, 0), nil // add one month
|
||||
case tmStr == "*monthly_estimated":
|
||||
initialMnt := time.Now().Month()
|
||||
tAfter := time.Now().AddDate(0, 1, 0)
|
||||
for tAfter.Month()-initialMnt > 1 {
|
||||
tAfter = tAfter.AddDate(0, 0, -1)
|
||||
}
|
||||
return tAfter, nil
|
||||
case tmStr == "*yearly":
|
||||
return time.Now().AddDate(1, 0, 0), nil // add one year
|
||||
|
||||
case strings.HasPrefix(tmStr, "*month_end"):
|
||||
expDate := GetEndOfMonth(time.Now())
|
||||
extraDur, err := getAddDuration(tmStr)
|
||||
|
||||
@@ -407,6 +407,19 @@ func TestParseTimeDetectLayout(t *testing.T) {
|
||||
} else if expected.Sub(date).Seconds() > 1 {
|
||||
t.Errorf("received: %+v", date)
|
||||
}
|
||||
|
||||
expected = time.Now().AddDate(0, 1, 0)
|
||||
if date, err := ParseTimeDetectLayout("*monthly_estimated", ""); err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
for date.Month()-expected.Month() > 1 {
|
||||
expected = expected.AddDate(0, 0, -1)
|
||||
}
|
||||
if expected.Sub(date).Seconds() > 1 {
|
||||
t.Errorf("received: %+v", date)
|
||||
}
|
||||
}
|
||||
|
||||
expected = time.Now().AddDate(0, 1, 0)
|
||||
if date, err := ParseTimeDetectLayout("*mo", ""); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -252,5 +251,4 @@ func TestDynamicDataProviderGetFullFieldPath(t *testing.T) {
|
||||
if newpath == nil {
|
||||
t.Errorf("Expected: %v,received %q", nil, newpath)
|
||||
}
|
||||
fmt.Println(*newpath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user