Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues #2980 #2994

Merged
merged 3 commits into from Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions util/gconv/gconv_struct.go
Expand Up @@ -388,6 +388,15 @@ func bindVarToStructAttr(structReflectValue reflect.Value, attrName string, valu
ReferValue: structFieldValue,
})
return
// Hold the time zone consistent in recursive
// Issue: https://github.com/gogf/gf/issues/2980
case "*gtime.Time", "gtime.Time":
doConvertWithReflectValueSet(structFieldValue, doConvertInput{
FromValue: value,
ToTypeName: structFieldTypeName,
ReferValue: structFieldValue,
})
return
}

// Try to call custom converter.
Expand Down
25 changes: 25 additions & 0 deletions util/gconv/gconv_z_unit_struct_test.go
Expand Up @@ -1303,6 +1303,31 @@ func Test_Struct_Issue1597(t *testing.T) {
})
}

// https://github.com/gogf/gf/issues/2980
func Test_Struct_Issue2980(t *testing.T) {
type Post struct {
CreatedAt *gtime.Time `json:"createdAt" `
}

type PostWithUser struct {
Post
UserName string `json:"UserName"`
}

gtest.C(t, func(t *gtest.T) {
date := gtime.New("2023-09-22 12:00:00").UTC()
params := g.Map{
"CreatedAt": gtime.New("2023-09-22 12:00:00").UTC(),
"UserName": "Galileo",
}
postWithUser := new(PostWithUser)
err := gconv.Scan(params, postWithUser)
t.AssertNil(err)
t.Assert(date.Location(), postWithUser.CreatedAt.Location())
t.Assert(date.Unix(), postWithUser.CreatedAt.Unix())
})
}

func Test_Scan_WithDoubleSliceAttribute(t *testing.T) {
inputData := [][]string{
{"aa", "bb", "cc"},
Expand Down