From 2e4ab441228d4c9e8940dd2162c0a674f3dc69f3 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Sat, 7 Oct 2023 10:34:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20super=20=E5=8C=85=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=80=9A=E8=BF=87=20MarshalToTargetWithJSON=20=E5=B0=86?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E9=80=9A=E8=BF=87=20JSON=20=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E4=B8=BA=E7=9B=AE=E6=A0=87=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/super/json.go | 5 +++++ utils/times/period.go | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/super/json.go b/utils/super/json.go index 5f505b5..70e375e 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 48ba21c..1bf769c 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} }