Skip to content

Commit

Permalink
feat: super 包支持通过 MarshalToTargetWithJSON 将对象通过 JSON 序列化为目标对象
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Oct 7, 2023
1 parent 05f0016 commit 2e4ab44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 5 additions & 0 deletions utils/super/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ func MarshalIndentJSON(v interface{}, prefix, indent string) []byte {
}
return b
}

// MarshalToTargetWithJSON 将对象转换为目标对象
func MarshalToTargetWithJSON(src, dest interface{}) error {
return json.Unmarshal(MarshalJSON(src), dest)
}
7 changes: 1 addition & 6 deletions utils/times/period.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ func NewPeriod(start, end time.Time) Period {

// NewPeriodWindow 创建一个特定长度的时间窗口
func NewPeriodWindow(t time.Time, size time.Duration) Period {
var start time.Time
if size < time.Minute {
start = t
} else {
start = t.Truncate(time.Minute)
}
start := t.Truncate(size)
end := start.Add(size)
return Period{start, end}
}
Expand Down

0 comments on commit 2e4ab44

Please sign in to comment.