mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
storing activation times with nanosecond precision
This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const LAYOUT = "2006-01-02T15:04:05Z07:00"
|
||||
|
||||
/*
|
||||
The struture that is saved to storage.
|
||||
*/
|
||||
@@ -29,7 +27,7 @@ func (ap *ActivationPeriod) AddInterval(is ...*Interval) {
|
||||
Serializes the objects for the storage.
|
||||
*/
|
||||
func (ap *ActivationPeriod) store() (result string) {
|
||||
result += ap.ActivationTime.Format(LAYOUT) + ";"
|
||||
result += strconv.FormatInt(ap.ActivationTime.UnixNano(), 10) + ";"
|
||||
var is string
|
||||
for _, i := range ap.Intervals {
|
||||
is = strconv.Itoa(int(i.Month)) + "|"
|
||||
@@ -54,7 +52,8 @@ De-serializes the objects for the storage.
|
||||
*/
|
||||
func (ap *ActivationPeriod) restore(input string) {
|
||||
elements := strings.Split(input, ";")
|
||||
ap.ActivationTime, _ = time.Parse(LAYOUT, elements[0])
|
||||
unixNano, _ := strconv.ParseInt(elements[0], 10, 64)
|
||||
ap.ActivationTime = time.Unix(0, unixNano).In(time.UTC)
|
||||
for _, is := range elements[1 : len(elements)-1] {
|
||||
i := &Interval{}
|
||||
ise := strings.Split(is, "|")
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestApStoreRestore(t *testing.T) {
|
||||
ap := ActivationPeriod{ActivationTime: d}
|
||||
ap.AddInterval(i)
|
||||
result := ap.store()
|
||||
expected := "2012-02-01T14:30:01Z;2|1|3,4|14:30:00|15:00:00|0|0|0|0;"
|
||||
expected := "1328106601000000000;2|1|3,4|14:30:00|15:00:00|0|0|0|0;"
|
||||
if result != expected {
|
||||
t.Errorf("Expected %q was %q", expected, result)
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestEverything(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkIntervalFull(b *testing.B) {
|
||||
func BenchmarkIntervalContainsDate(b *testing.B) {
|
||||
i := &Interval{Month: time.February, MonthDay: 1, WeekDays: []time.Weekday{time.Wednesday, time.Thursday}, StartTime: "14:30:00", EndTime: "15:00:00"}
|
||||
d := time.Date(2012, time.February, 1, 14, 30, 0, 0, time.UTC)
|
||||
for x := 0; x < b.N; x++ {
|
||||
|
||||
Binary file not shown.
@@ -1,8 +1,6 @@
|
||||
[
|
||||
{"TOR": 0,"CstmId":"vdf","Subject":"rif","DestinationPrefix":"0256","TimeEnd":"0001-01-01T00:00:00Z","TimeStart":"0001-01-01T00:00:00Z",
|
||||
"ActivationPeriods": [
|
||||
{"ActivationTime": "2012-01-01T00:00:00Z",
|
||||
"Intervals": [
|
||||
{"TOR": 0,"CstmId":"vdf","Subject":"rif","DestinationPrefix":"0256", "ActivationPeriods": [
|
||||
{"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [
|
||||
{"BillingUnit":1,"ConnectFee":0,"EndTime":"18:00:00","Month":0,"MonthDay":0,"Ponder":0,"Price":0.2,"StartTime":"","WeekDays":[1,2,3,4,5]},
|
||||
{"BillingUnit":1,"ConnectFee":0,"EndTime":"","Month":0,"MonthDay":0,"Ponder":0,"Price":0.1,"StartTime":"18:00:00","WeekDays":[1,2,3,4,5]},
|
||||
{"BillingUnit":1,"ConnectFee":0,"EndTime":"","Month":0,"MonthDay":0,"Ponder":0,"Price":0.1,"StartTime":"","WeekDays":[6,0]}
|
||||
@@ -10,10 +8,8 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{"TOR": 0,"CstmId":"vdf","Subject":"rif","DestinationPrefix":"0257","TimeEnd":"0001-01-01T00:00:00Z","TimeStart":"0001-01-01T00:00:00Z",
|
||||
"ActivationPeriods": [
|
||||
{"ActivationTime": "2012-01-01T00:00:00Z",
|
||||
"Intervals": [
|
||||
{"TOR": 0,"CstmId":"vdf","Subject":"rif","DestinationPrefix":"0257", "ActivationPeriods": [
|
||||
{"ActivationTime": "2012-01-01T00:00:00Z", "Intervals": [
|
||||
{"BillingUnit":1,"ConnectFee":0,"EndTime":"","Month":0,"MonthDay":0,"Ponder":0,"Price":0.1,"StartTime":"18:00:00","WeekDays":[1,2,3,4,5]},
|
||||
{"BillingUnit":1,"ConnectFee":0,"EndTime":"18:00:00","Month":0,"MonthDay":0,"Ponder":0,"Price":0.2,"StartTime":"","WeekDays":[1,2,3,4,5]},
|
||||
{"BillingUnit":1,"ConnectFee":0,"EndTime":"","Month":0,"MonthDay":0,"Ponder":0,"Price":0.1,"StartTime":"","WeekDays":[6,0]}
|
||||
@@ -21,4 +17,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user