serialization still not working

This commit is contained in:
Radu Ioan Fericean
2012-02-04 13:56:55 +02:00
parent 7b3a25a02d
commit b4a82e0538
2 changed files with 6 additions and 8 deletions

View File

@@ -24,7 +24,7 @@ func (ap *ActivationPeriod) AddInterval(is ...*Interval) {
}
func (ap *ActivationPeriod) Store() (result string){
result += strconv.FormatInt(ap.ActivationTime.Unix(), 10) + ","+ strconv.FormatInt(ap.ActivationTime.UnixNano(), 10) + ";"
result += strconv.FormatInt(ap.ActivationTime.Unix(), 10) + ";"
var is string
for _,i := range ap.Intervals {
is = strconv.Itoa(int(i.Month)) + "|"
@@ -45,11 +45,9 @@ func (ap *ActivationPeriod) Store() (result string){
}
func (ap *ActivationPeriod) Restore(input string) {
elements := strings.Split(input, ";")
at := strings.Split(elements[0], ",")
unix, _ := strconv.ParseInt(at[0], 0, 64)
unixNano, _ := strconv.ParseInt(at[1], 0, 64)
ap.ActivationTime = time.Unix(unix, unixNano)
elements := strings.Split(input, ";")
unix, _ := strconv.ParseInt(elements[0], 0, 64)
ap.ActivationTime = time.Unix(unix, 0)
for _, is := range elements[1:len(elements) - 1]{
i := &Interval{}
ise := strings.Split(is, "|")

View File

@@ -82,14 +82,14 @@ func TestApStoreRestore(t *testing.T) {
ap := ActivationPeriod{ActivationTime: d}
ap.AddInterval(i)
result := ap.Store()
expected := "1328106601,1328106601000000000;2|1||14:30:00|15:00:00|0|0|0|0;"
expected := "1328106601;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)
}
ap1 := ActivationPeriod{}
ap1.Restore(result)
if ap1.ActivationTime != ap.ActivationTime {
//t.Errorf("Expected %v was %v", ap.ActivationTime, ap1.ActivationTime)
t.Errorf("Expected %v was %v", ap.ActivationTime, ap1.ActivationTime)
}
i1 := ap1.Intervals[0]
if i1.Month != i.Month {