Skip to content

Commit

Permalink
feat: timer 包新增 GetCurrWeekDate 和 GetLastWeekDate 函数
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Jan 31, 2024
1 parent c95b206 commit ad4777a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions utils/times/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ const (
Week = Day * 7
)

// GetCurrWeekDate 获取以 week 为周一的本周 week 时间
func GetCurrWeekDate(now time.Time, week time.Weekday) time.Time {
w := int(week)
monday := GetMondayZero(now)
var curr time.Time
if WeekDay(now) > w {
curr = monday.AddDate(0, 0, w-1)
} else {
curr = monday.AddDate(0, 0, w-1)
curr = curr.AddDate(0, 0, -7)
}
return curr
}

// GetLastWeekDate 获取以 week 为周一的特定时间 now 的上周 week 时间
func GetLastWeekDate(now time.Time, week time.Weekday) time.Time {
w := int(week)
monday := GetMondayZero(now)
var last time.Time
if WeekDay(now) > w {
last = monday.AddDate(0, 0, -(7 - w + 1))
} else {
last = monday.AddDate(0, 0, -(7 - w + 1))
last = last.AddDate(0, 0, -7)
}
return last
}

// GetMonthDays 获取一个时间当月共有多少天
func GetMonthDays(t time.Time) int {
t = GetToday(t)
Expand Down

0 comments on commit ad4777a

Please sign in to comment.