Skip to content

Commit

Permalink
fix(encoding/form): Timestamp use local time and fix test wrong moc…
Browse files Browse the repository at this point in the history
…k time zone (#3257)

* fix(form/test): wrong mock time zone

* fix lint
  • Loading branch information
demoManito authored Mar 22, 2024
1 parent bfafeca commit aeecf3c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
6 changes: 1 addition & 5 deletions encoding/form/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ func TestFormCodecUnmarshal(t *testing.T) {
}

func TestProtoEncodeDecode(t *testing.T) {
loc := time.Local
time.Local = time.UTC
t.Cleanup(func() { time.Local = loc })

in := &complex.Complex{
Id: 2233,
NoOne: "2233",
Expand All @@ -106,7 +102,7 @@ func TestProtoEncodeDecode(t *testing.T) {
Byte: []byte("123"),
Map: map[string]string{"kratos": "https://go-kratos.dev/", "kratos_start": "https://go-kratos.dev/en/docs/getting-started/start/"},

Timestamp: &timestamppb.Timestamp{Seconds: 20, Nanos: 2},
Timestamp: timestamppb.New(time.Date(1970, 1, 1, 0, 0, 20, 2, time.Local)),
Duration: &durationpb.Duration{Seconds: 120, Nanos: 22},
Field: &fieldmaskpb.FieldMask{Paths: []string{"1", "2"}},
Double: &wrapperspb.DoubleValue{Value: 12.33},
Expand Down
2 changes: 1 addition & 1 deletion encoding/form/proto_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func parseMessage(md protoreflect.MessageDescriptor, value string) (protoreflect
if value == nullStr {
break
}
t, err := time.Parse(time.RFC3339Nano, value)
t, err := time.ParseInLocation(time.RFC3339Nano, value, time.Local)
if err != nil {
return protoreflect.Value{}, err
}
Expand Down
6 changes: 1 addition & 5 deletions encoding/form/proto_encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
)

func TestEncodeValues(t *testing.T) {
loc := time.Local
time.Local = time.UTC
t.Cleanup(func() { time.Local = loc })

in := &complex.Complex{
Id: 2233,
NoOne: "2233",
Expand All @@ -33,7 +29,7 @@ func TestEncodeValues(t *testing.T) {
Map: map[string]string{"kratos": "https://go-kratos.dev/", "kratos_start": "https://go-kratos.dev/en/docs/getting-started/start/"},
MapInt64Key: map[int64]string{1: "kratos", 2: "go-zero"},

Timestamp: &timestamppb.Timestamp{Seconds: 20, Nanos: 2},
Timestamp: timestamppb.New(time.Date(1970, 1, 1, 0, 0, 20, 2, time.Local)),
Duration: &durationpb.Duration{Seconds: 120, Nanos: 22},
Field: &fieldmaskpb.FieldMask{Paths: []string{"1", "2"}},
Double: &wrapperspb.DoubleValue{Value: 12.33},
Expand Down

0 comments on commit aeecf3c

Please sign in to comment.