From b41023203e4c038cf607a91a719370c99fc1c5f7 Mon Sep 17 00:00:00 2001 From: demoManito <1430482733@qq.com> Date: Wed, 21 Jun 2023 16:43:57 +0800 Subject: [PATCH] fix(encoding/form): time with the location set to local time --- encoding/form/well_known_types.go | 2 +- encoding/form/well_known_types_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/encoding/form/well_known_types.go b/encoding/form/well_known_types.go index 8b0894dbf..4690bdd1f 100644 --- a/encoding/form/well_known_types.go +++ b/encoding/form/well_known_types.go @@ -52,7 +52,7 @@ func marshalTimestamp(m protoreflect.Message) (string, error) { } // Uses RFC 3339, where generated output will be Z-normalized and uses 0, 3, // 6 or 9 fractional digits. - t := time.Unix(secs, nanos).UTC() + t := time.Unix(secs, nanos).Local() x := t.Format("2006-01-02T15:04:05.000000000") x = strings.TrimSuffix(x, "000") x = strings.TrimSuffix(x, "000") diff --git a/encoding/form/well_known_types_test.go b/encoding/form/well_known_types_test.go index 5018cf7a0..ce5e970c9 100644 --- a/encoding/form/well_known_types_test.go +++ b/encoding/form/well_known_types_test.go @@ -17,11 +17,11 @@ func TestMarshalTimeStamp(t *testing.T) { expect string }{ { - input: timestamppb.New(time.Date(2022, 1, 2, 3, 4, 5, 6, time.UTC)), + input: timestamppb.New(time.Date(2022, 1, 2, 3, 4, 5, 6, time.Local)), expect: "2022-01-02T03:04:05.000000006Z", }, { - input: timestamppb.New(time.Date(2022, 13, 1, 13, 61, 61, 100, time.UTC)), + input: timestamppb.New(time.Date(2022, 13, 1, 13, 61, 61, 100, time.Local)), expect: "2023-01-01T14:02:01.000000100Z", }, }