feat: super 包支持通过 MarshalToTargetWithJSON 将对象通过 JSON 序列化为目标对象

This commit is contained in:
kercylan98 2023-10-07 10:34:05 +08:00
parent 05f0016b7e
commit 2e4ab44122
2 changed files with 6 additions and 6 deletions

View File

@ -46,3 +46,8 @@ func MarshalIndentJSON(v interface{}, prefix, indent string) []byte {
} }
return b return b
} }
// MarshalToTargetWithJSON 将对象转换为目标对象
func MarshalToTargetWithJSON(src, dest interface{}) error {
return json.Unmarshal(MarshalJSON(src), dest)
}

View File

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