From 66bb56486335058b161cfeb05c3ea98294a805e3 Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Mon, 12 Feb 2024 17:25:58 +0000 Subject: [PATCH] fix(bigquery): align return time.Time values to UTC The changes in https://github.com/googleapis/google-cloud-go/pull/9368 changed the expectation that constructed time.Time objects would use UTC time for location. This PR returns to the old behavior by forcing the values to be returned aligned to UTC time, and avoid using the local timezone for construction. Fixes: https://github.com/googleapis/google-cloud-go/issues/9407 --- bigquery/value.go | 2 +- bigquery/value_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bigquery/value.go b/bigquery/value.go index ec6c26996c86..34070d033f99 100644 --- a/bigquery/value.go +++ b/bigquery/value.go @@ -958,7 +958,7 @@ func convertBasicType(val string, typ FieldType) (Value, error) { if err != nil { return nil, err } - return time.UnixMicro(i), nil + return time.UnixMicro(i).UTC(), nil case DateFieldType: return civil.ParseDate(val) case TimeFieldType: diff --git a/bigquery/value_test.go b/bigquery/value_test.go index d6db62b8fd9d..57c3429d13e3 100644 --- a/bigquery/value_test.go +++ b/bigquery/value_test.go @@ -95,6 +95,11 @@ func TestConvertTime(t *testing.T) { t.Errorf("#%d: got:\n%v\nwant:\n%v", i, g, w) } } + // Ensure that the times are returned in UTC timezone. + // https://github.com/googleapis/google-cloud-go/issues/9407 + if gotTZ := got[0].(time.Time).Location(); gotTZ != time.UTC { + t.Errorf("expected time zone UTC: got:\n%v", gotTZ) + } } func TestConvertSmallTimes(t *testing.T) {