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

Unified Diff: service/datastore/properties.go

Issue 1289323002: Fix miscellaneous prod bugs. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Rebase. Created 5 years, 4 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 | « service/datastore/pls_test.go ('k') | service/datastore/properties_test.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 8ce5970def31e1939b3f69638c85bfca264e00de..44a4361ed895051e1516fb364d810027acfb0952 100644
--- a/service/datastore/properties.go
+++ b/service/datastore/properties.go
@@ -17,6 +17,8 @@ import (
var (
minTime = time.Unix(int64(math.MinInt64)/1e6, (int64(math.MinInt64)%1e6)*1e3)
maxTime = time.Unix(int64(math.MaxInt64)/1e6, (int64(math.MaxInt64)%1e6)*1e3)
+
+ utcTestTime = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
)
// IndexSetting indicates whether or not a Property should be indexed by the
@@ -206,8 +208,8 @@ func PropertyTypeOf(v interface{}, checkValid bool) (PropertyType, error) {
if checkValid && (x.Before(minTime) || x.After(maxTime)) {
err = errors.New("time value out of range")
}
- if checkValid && x.Location() != time.UTC {
- err = fmt.Errorf("time value has wrong Location: %s", x.Location())
+ if checkValid && !timeLocationIsUTC(x.Location()) {
+ err = fmt.Errorf("time value has wrong Location: %v %v", x.Location())
}
return PTTime, err
case GeoPoint:
@@ -221,6 +223,16 @@ func PropertyTypeOf(v interface{}, checkValid bool) (PropertyType, error) {
}
}
+// timeLocationsEqual 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
+// time. To compensate, we instantiate two new time.Time using the respective
+// Locations.
+func timeLocationIsUTC(l *time.Location) bool {
+ return time.Date(1970, 1, 1, 0, 0, 0, 0, l).Equal(utcTestTime)
+}
+
// UpconvertUnderlyingType takes an object o, and attempts to convert it to
// its native datastore-compatible type. e.g. int16 will convert to int64, and
// `type Foo string` will convert to `string`.
« no previous file with comments | « service/datastore/pls_test.go ('k') | service/datastore/properties_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698