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

Unified Diff: service/datastore/properties.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/prod/raw_datastore_type_converter_test.go ('k') | service/datastore/serialize/serialize.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/properties.go
diff --git a/service/datastore/properties.go b/service/datastore/properties.go
index 770d19b0f2b4c1e86995f6239a0c9afe7256eb12..d42c098b0ff4c618fe2e271f2e9ba39775b4b861 100644
--- a/service/datastore/properties.go
+++ b/service/datastore/properties.go
@@ -270,7 +270,7 @@ func PropertyTypeOf(v interface{}, checkValid bool) (PropertyType, error) {
}
}
-// timeLocationsEqual tests if two time.Location are equal.
+// timeLocationIsUTC tests if two time.Location are equal.
//
// This is tricky using the standard time API, as time is implicitly normalized
// to UTC and all equality checks are performed relative to that normalized
@@ -308,7 +308,10 @@ func UpconvertUnderlyingType(o interface{}) interface{} {
case reflect.Struct:
if t == typeOfTime {
// time in a Property can only hold microseconds
- o = v.Interface().(time.Time).Round(time.Microsecond)
+ tim := v.Interface().(time.Time)
+ if !tim.IsZero() {
+ o = v.Interface().(time.Time).Round(time.Microsecond)
+ }
}
}
return o
@@ -409,7 +412,11 @@ func (p *Property) Project(to PropertyType) (interface{}, error) {
case to == PTTime && p.propType == PTInt:
v := p.value.(int64)
- return time.Unix(int64(v/1e6), int64((v%1e6)*1e3)).UTC(), nil
+ t := time.Unix(int64(v/1e6), int64((v%1e6)*1e3))
+ if t.IsZero() {
+ return time.Time{}, nil
+ }
+ return t.UTC(), nil
case to == PTString && p.propType == PTBytes:
return string(p.value.([]byte)), nil
« no previous file with comments | « impl/prod/raw_datastore_type_converter_test.go ('k') | service/datastore/serialize/serialize.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698