Browse Source

codec: cbor: no need to Round time twice - once is sufficient.

Ugorji Nwoke 8 years ago
parent
commit
248efabedf
2 changed files with 3 additions and 3 deletions
  1. 2 2
      codec/cbor.go
  2. 1 1
      codec/codec_test.go

+ 2 - 2
codec/cbor.go

@@ -133,7 +133,7 @@ func (e *cborEncDriver) EncodeTime(t time.Time) {
 		e.EncodeString(cUTF8, t.Format(time.RFC3339Nano))
 	} else {
 		e.encUint(1, cborBaseTag)
-		t = t.UTC().Round(0).Round(time.Microsecond)
+		t = t.UTC().Round(time.Microsecond)
 		sec, nsec := t.Unix(), uint64(t.Nanosecond())
 		if nsec == 0 {
 			e.EncodeInt(sec)
@@ -558,7 +558,7 @@ func (d *cborDecDriver) decodeTime(xtag uint64) (t time.Time) {
 	default:
 		d.d.errorf("cbor: invalid tag for time.Time - expecting 0 or 1, got 0x%x", xtag)
 	}
-	t = t.Round(time.Microsecond).UTC()
+	t = t.UTC().Round(time.Microsecond)
 	return
 }
 

+ 1 - 1
codec/codec_test.go

@@ -624,7 +624,7 @@ func testVerifyVal(v interface{}, f testVerifyFlag, h Handle) (v2 interface{}) {
 			v2 = iv.UTC()
 		case isCbor:
 			// fmt.Printf("%%%% cbor verifier\n")
-			v2 = iv.UTC().Round(0).Round(time.Microsecond)
+			v2 = iv.UTC().Round(time.Microsecond)
 		default:
 			v2 = v
 		}