added activation time with + and * stuff

This commit is contained in:
Radu Ioan Fericean
2013-07-30 23:06:31 +03:00
parent 11e7eed149
commit 1d3ce69c5d
9 changed files with 51 additions and 43 deletions

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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))
}
}