diff --git a/utils/super/json.go b/utils/super/json.go index 5f505b5e..70e375e5 100644 --- a/utils/super/json.go +++ b/utils/super/json.go @@ -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) +} diff --git a/utils/times/period.go b/utils/times/period.go index 48ba21ce..1bf769cb 100644 --- a/utils/times/period.go +++ b/utils/times/period.go @@ -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} }