Skip to content

Commit

Permalink
fix issues #2980 (#2994)
Browse files Browse the repository at this point in the history
  • Loading branch information
oldme-git committed Oct 11, 2023
1 parent 3cd0059 commit 10b67fc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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

0 comments on commit 10b67fc

Please sign in to comment.