OLD | NEW |
---|---|
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 datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "encoding/base64" | 8 "encoding/base64" |
9 "errors" | 9 "errors" |
10 "fmt" | 10 "fmt" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 err := error(nil) | 238 err := error(nil) |
239 if checkValid && !x.Valid() { | 239 if checkValid && !x.Valid() { |
240 err = errors.New("invalid GeoPoint value") | 240 err = errors.New("invalid GeoPoint value") |
241 } | 241 } |
242 return PTGeoPoint, err | 242 return PTGeoPoint, err |
243 default: | 243 default: |
244 return PTUnknown, fmt.Errorf("gae: Property has bad type %T", v) | 244 return PTUnknown, fmt.Errorf("gae: Property has bad type %T", v) |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 // RoundTime rounds a time.Time to microseconds, which is the (undocumented) | |
249 // way that the AppEngine SDK stores it. | |
250 func RoundTime(t time.Time) time.Time { | |
dnj
2015/12/29 21:40:47
I'm adding this and exporting it b/c this is somet
| |
251 return t.Round(time.Microsecond) | |
252 } | |
253 | |
248 // timeLocationIsUTC tests if two time.Location are equal. | 254 // timeLocationIsUTC tests if two time.Location are equal. |
249 // | 255 // |
250 // This is tricky using the standard time API, as time is implicitly normalized | 256 // This is tricky using the standard time API, as time is implicitly normalized |
251 // to UTC and all equality checks are performed relative to that normalized | 257 // to UTC and all equality checks are performed relative to that normalized |
252 // time. To compensate, we instantiate two new time.Time using the respective | 258 // time. To compensate, we instantiate two new time.Time using the respective |
253 // Locations. | 259 // Locations. |
254 func timeLocationIsUTC(l *time.Location) bool { | 260 func timeLocationIsUTC(l *time.Location) bool { |
255 return time.Date(1970, 1, 1, 0, 0, 0, 0, l).Equal(utcTestTime) | 261 return time.Date(1970, 1, 1, 0, 0, 0, 0, l).Equal(utcTestTime) |
256 } | 262 } |
257 | 263 |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 // Example: | 827 // Example: |
822 // pls.GetMetaDefault("foo", 100).(int64) | 828 // pls.GetMetaDefault("foo", 100).(int64) |
823 func GetMetaDefault(getter MetaGetter, key string, dflt interface{}) interface{} { | 829 func GetMetaDefault(getter MetaGetter, key string, dflt interface{}) interface{} { |
824 dflt = UpconvertUnderlyingType(dflt) | 830 dflt = UpconvertUnderlyingType(dflt) |
825 cur, ok := getter.GetMeta(key) | 831 cur, ok := getter.GetMeta(key) |
826 if !ok || (dflt != nil && reflect.TypeOf(cur) != reflect.TypeOf(dflt)) { | 832 if !ok || (dflt != nil && reflect.TypeOf(cur) != reflect.TypeOf(dflt)) { |
827 return dflt | 833 return dflt |
828 } | 834 } |
829 return cur | 835 return cur |
830 } | 836 } |
OLD | NEW |