Skip to content

Commit

Permalink
fix(encoding/form): time with the location set to local time (#2885)
Browse files Browse the repository at this point in the history
  • Loading branch information
demoManito authored Dec 16, 2023
1 parent 5ec8524 commit 856bc9a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion encoding/form/well_known_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions encoding/form/well_known_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
Expand Down

0 comments on commit 856bc9a

Please sign in to comment.