Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datastore): Ensure the datastore time is returned as UTC #3521

Merged
merged 10 commits into from Jan 13, 2021
45 changes: 30 additions & 15 deletions datastore/load_test.go
Expand Up @@ -486,21 +486,6 @@ func TestLoadToInterface(t *testing.T) {
dst: &withUntypedInterface{Field: 1e9},
want: &withUntypedInterface{Field: "Newly set"},
},
{
name: "struct with timestamp",
src: &pb.Entity{
Key: keyToProto(testKey0),
Properties: map[string]*pb.Value{
"Time": {ValueType: &pb.Value_TimestampValue{TimestampValue: &timestamppb.Timestamp{Seconds: 1605504600}}},
},
},
dst: &struct{ Time time.Time }{
Time: time.Time{},
},
want: &struct{ Time time.Time }{
Time: time.Unix(1605504600, 0).In(time.UTC),
},
},
{
name: "struct with civil.Date",
src: &pb.Entity{
Expand Down Expand Up @@ -584,6 +569,36 @@ func TestLoadToInterface(t *testing.T) {
}
}

func TestTimezone(t *testing.T) {
// Expect Local times to be represented in UTC
crwilcox marked this conversation as resolved.
Show resolved Hide resolved
src := &pb.Entity{
Key: keyToProto(testKey0),
Properties: map[string]*pb.Value{
"Time": {ValueType: &pb.Value_TimestampValue{TimestampValue: &timestamppb.Timestamp{Seconds: 1605504600}}},
},
}

dst := &struct{ Time time.Time }{
Time: time.Time{},
}
want := &struct{ Time time.Time }{
Time: time.Unix(1605504600, 0).In(time.UTC),
}

err := loadEntityProto(dst, src)

if err != nil {
t.Fatalf("loadEntityProto: %v", err)
}

gotZone, _ := dst.Time.Zone()
crwilcox marked this conversation as resolved.
Show resolved Hide resolved
wantZone, _ := want.Time.Zone()
if diff := testutil.Diff(gotZone, wantZone); diff != "" {
t.Fatalf("Mismatch: got - want +\n%s", diff)
}

}

func TestAlreadyPopulatedDst(t *testing.T) {
testCases := []struct {
desc string
Expand Down