From 3eccd42cdf62d453fc6601bc2f4c4dc1279cbad1 Mon Sep 17 00:00:00 2001 From: liwei <2211068034@qq.com> Date: Wed, 19 Jul 2023 19:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=91=A8=E9=95=BF=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/time.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/utils/time.go b/utils/time.go index e06c19155..0534e3538 100644 --- a/utils/time.go +++ b/utils/time.go @@ -18,18 +18,23 @@ func IsToday(d int64) bool { // 判断是否是出于同一周 func IsSameWeek(d int64) bool { - // 将时间戳转换成一个 time.Time 对象 - t1 := time.Unix(d, 0) - t2 := configure.Now() + // 将时间戳转换为 time.Time 类型 + time1 := time.Unix(d, 0) + time2 := configure.Now() - // 获取 t1 所在的周的第一天和 t2 所在的周的第一天 - t1FirstDay := t1.AddDate(0, 0, -int(t1.Weekday())+1) - t2FirstDay := t2.AddDate(0, 0, -int(t2.Weekday())+1) - // 判断两个时间所在的周的第一天是否相同 - return t1FirstDay.Equal(t2FirstDay) + // 获取时间戳所属的年份和周数 + year1, week1 := time1.ISOWeek() + year2, week2 := time2.ISOWeek() + + // 判断是否同一年同一周 + if year1 == year2 && week1 == week2 { + return true + } else { + return false + } } -//判断是否大于1周 +// 判断是否大于1周 func IsAfterWeek(d int64) bool { tt := time.Unix(d, 0) nowt := configure.Now() @@ -138,7 +143,7 @@ func GetTodayZeroTime(curTime int64) int64 { return startTime.Unix() } -// 计算自然天数 +// 计算自然天数 func DiffDays(t1, t2 int64) int { if t1 == t2 { return -1