mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 00:58:45 +05:00
added activation time with + and * stuff
This commit is contained in:
@@ -72,7 +72,7 @@ type TPRatingProfile struct {
|
||||
}
|
||||
|
||||
type RatingActivation struct {
|
||||
ActivationTime int64 // Time when this profile will become active, defined as unix epoch time
|
||||
ActivationTime string // Time when this profile will become active, defined as unix epoch time
|
||||
DestRateTimingId string // Id of DestRateTiming profile
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
@@ -108,6 +109,8 @@ func ParseDate(date string) (expDate time.Time, err error) {
|
||||
expDate = time.Now().Add(d)
|
||||
case string(expirationTime) == "*monthly":
|
||||
expDate = time.Now().AddDate(0, 1, 0) // add one month
|
||||
case bytes.Contains(expirationTime, []byte("Z")):
|
||||
expDate, err = time.Parse(time.RFC3339, date)
|
||||
default:
|
||||
unix, err := strconv.ParseInt(string(expirationTime), 10, 64)
|
||||
if err != nil {
|
||||
|
||||
@@ -150,3 +150,11 @@ func TestParseDateMonthly(t *testing.T) {
|
||||
t.Error("error parsing date: ", expected.Sub(date).Seconds())
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDateRFC3339(t *testing.T) {
|
||||
date, err := ParseDate("2013-07-30T19:33:10Z")
|
||||
expected := time.Date(2013, 7, 30, 19, 33, 10, 0, time.UTC)
|
||||
if err != nil || !date.Equal(expected) {
|
||||
t.Error("error parsing date: ", expected.Sub(date))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user