Browse Source

Store zero time as blank bytes

Matt Heath 10 years ago
parent
commit
04792dd413
2 changed files with 9 additions and 0 deletions
  1. 3 0
      marshal.go
  2. 6 0
      marshal_test.go

+ 3 - 0
marshal.go

@@ -802,6 +802,9 @@ func marshalTimestamp(info TypeInfo, value interface{}) ([]byte, error) {
 	case int64:
 		return encBigInt(v), nil
 	case time.Time:
+		if v.IsZero() {
+			return []byte{}, nil
+		}
 		x := int64(v.UTC().Unix()*1e3) + int64(v.UTC().Nanosecond()/1e6)
 		return encBigInt(x), nil
 	}

+ 6 - 0
marshal_test.go

@@ -839,6 +839,12 @@ func TestMarshalTimestamp(t *testing.T) {
 			[]byte("\xff\xff\xf7\x9c\x84\x2f\xa5\x09"),
 			time.Date(1677, time.September, 21, 00, 12, 43, 145224191, time.UTC),
 		},
+		{
+			// Store the zero time as a blank slice
+			NativeType{proto: 2, typ: TypeTimestamp},
+			[]byte{},
+			time.Time{},
+		},
 	}
 
 	for i, test := range marshalTimestampTests {