feat: timer 包新增 GetCurrWeekDate 和 GetLastWeekDate 函数
This commit is contained in:
parent
c95b206592
commit
ad4777a379
|
@ -15,6 +15,34 @@ const (
|
||||||
Week = Day * 7
|
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 获取一个时间当月共有多少天
|
// GetMonthDays 获取一个时间当月共有多少天
|
||||||
func GetMonthDays(t time.Time) int {
|
func GetMonthDays(t time.Time) int {
|
||||||
t = GetToday(t)
|
t = GetToday(t)
|
||||||
|
|
Loading…
Reference in New Issue