1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

fix(encoding/form): time with the location set to local time (#2885)

This commit is contained in:
jessetang 2023-12-16 17:21:43 +08:00 committed by GitHub
parent 5ec8524d5f
commit 856bc9a17b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -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")

View File

@ -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",
},
}