Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: service/datastore/serialize/serialize.go

Issue 1345043005: Fix zero time bug (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « service/datastore/properties.go ('k') | service/datastore/serialize/serialize_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package serialize 5 package serialize
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "errors" 9 "errors"
10 "fmt" 10 "fmt"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 _, err := cmpbin.WriteInt(buf, t.Unix()*1e6+int64(t.Nanosecond()/1e3)) 200 _, err := cmpbin.WriteInt(buf, t.Unix()*1e6+int64(t.Nanosecond()/1e3))
201 return err 201 return err
202 } 202 }
203 203
204 // ReadTime reads a time.Time from the buffer. 204 // ReadTime reads a time.Time from the buffer.
205 func ReadTime(buf Buffer) (time.Time, error) { 205 func ReadTime(buf Buffer) (time.Time, error) {
206 v, _, err := cmpbin.ReadInt(buf) 206 v, _, err := cmpbin.ReadInt(buf)
207 if err != nil { 207 if err != nil {
208 return time.Time{}, err 208 return time.Time{}, err
209 } 209 }
210 » return time.Unix(v/1e6, (v%1e6)*1e3).UTC(), nil 210 » t := time.Unix(v/1e6, (v%1e6)*1e3)
211 » if t.IsZero() {
212 » » return time.Time{}, nil
213 » }
214 » return t.UTC(), nil
211 } 215 }
212 216
213 // WriteProperty writes a Property to the buffer. `context` behaves the same 217 // WriteProperty writes a Property to the buffer. `context` behaves the same
214 // way that it does for WriteKey, but only has an effect if `p` contains a 218 // way that it does for WriteKey, but only has an effect if `p` contains a
215 // Key as its Value. 219 // Key as its Value.
216 func WriteProperty(buf Buffer, context KeyContext, p ds.Property) (err error) { 220 func WriteProperty(buf Buffer, context KeyContext, p ds.Property) (err error) {
217 defer recoverTo(&err) 221 defer recoverTo(&err)
218 typb := byte(p.Type()) 222 typb := byte(p.Type())
219 if p.IndexSetting() != ds.NoIndex { 223 if p.IndexSetting() != ds.NoIndex {
220 typb |= 0x80 224 typb |= 0x80
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 540 }
537 } 541 }
538 542
539 func recoverTo(err *error) { 543 func recoverTo(err *error) {
540 if r := recover(); r != nil { 544 if r := recover(); r != nil {
541 if rerr := r.(parseError); rerr != nil { 545 if rerr := r.(parseError); rerr != nil {
542 *err = error(rerr) 546 *err = error(rerr)
543 } 547 }
544 } 548 }
545 } 549 }
OLDNEW
« no previous file with comments | « service/datastore/properties.go ('k') | service/datastore/serialize/serialize_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698