diff --git a/timespans/calldesc.go b/timespans/calldesc.go index 882efd5fd..d19c2fae5 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -7,6 +7,8 @@ import ( "strconv" ) +const LAYOUT = "2006-01-02T15:04:05Z07:00" + /* The struture that is saved to storage. */ @@ -22,7 +24,7 @@ func (ap *ActivationPeriod) AddInterval(is ...*Interval) { } func (ap *ActivationPeriod) store() (result string){ - result += strconv.FormatInt(ap.ActivationTime.Unix(), 10) + ";" + result += ap.ActivationTime.Format(LAYOUT) + ";" var is string for _,i := range ap.Intervals { is = strconv.Itoa(int(i.Month)) + "|" @@ -44,8 +46,7 @@ func (ap *ActivationPeriod) store() (result string){ func (ap *ActivationPeriod) restore(input string) { elements := strings.Split(input, ";") - unix, _ := strconv.ParseInt(elements[0], 0, 64) - ap.ActivationTime = time.Unix(unix, 0) + ap.ActivationTime, _ = time.Parse(LAYOUT, elements[0]) for _, is := range elements[1:len(elements) - 1]{ i := &Interval{} ise := strings.Split(is, "|") diff --git a/timespans/calldesc_test.go b/timespans/calldesc_test.go index f44ae4dcc..bb4cea249 100644 --- a/timespans/calldesc_test.go +++ b/timespans/calldesc_test.go @@ -72,9 +72,8 @@ func TestRedisGetCost(t *testing.T) { } } -func TestApStoreRestore(t *testing.T) { - loc, _ := time.LoadLocation("Local") - d := time.Date(2012, time.February, 1, 14, 30, 1, 0, loc) +func TestApStoreRestore(t *testing.T) { + d := time.Date(2012, time.February, 1, 14, 30, 1, 0, time.UTC) i := &Interval{Month: time.February, MonthDay: 1, WeekDays: []time.Weekday{time.Wednesday, time.Thursday}, @@ -83,7 +82,7 @@ func TestApStoreRestore(t *testing.T) { ap := ActivationPeriod{ActivationTime: d} ap.AddInterval(i) result := ap.store() - expected := "1328099401;2|1|3,4|14:30:00|15:00:00|0|0|0|0;" + expected := "2012-02-01T14:30:01Z;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) } diff --git a/timespans/test.kch b/timespans/test.kch index 7a60d4399..fc0b932bc 100644 Binary files a/timespans/test.kch and b/timespans/test.kch differ