|
@@ -16,20 +16,20 @@ func Tomorrow() time.Time {
|
|
|
// 获取最近7天的日期范围
|
|
|
func Last7Days() (time.Time, time.Time) {
|
|
|
today := Today()
|
|
|
- return today.AddDate(0, 0, -6), today
|
|
|
+ return today.AddDate(0, 0, -6), today.Add(time.Hour * 23).Add(time.Minute * 59).Add(time.Second * 59)
|
|
|
}
|
|
|
|
|
|
// 获取上周的日期范围
|
|
|
func LastWeek() (time.Time, time.Time) {
|
|
|
start := Today().AddDate(0, 0, -7)
|
|
|
- end := start.AddDate(0, 0, 6)
|
|
|
+ end := start.AddDate(0, 0, 6).Add(time.Hour * 23).Add(time.Minute * 59).Add(time.Second * 59)
|
|
|
return start, end
|
|
|
}
|
|
|
|
|
|
// 获取本周的日期范围
|
|
|
func ThisWeek() (time.Time, time.Time) {
|
|
|
- start := time.Now().Round(0).Local().AddDate(0, 0, 0-int(time.Now().Weekday())+1) // 0是本周的第一天,+1是因为AddDate是相对于当前时间的
|
|
|
- end := start.AddDate(0, 0, 6)
|
|
|
+ start := Today().Round(0).Local().AddDate(0, 0, 0-int(time.Now().Weekday())+1) // 0是本周的第一天,+1是因为AddDate是相对于当前时间的
|
|
|
+ end := start.AddDate(0, 0, 6).Add(time.Hour * 23).Add(time.Minute * 59).Add(time.Second * 59)
|
|
|
return start, end
|
|
|
}
|
|
|
|
|
@@ -37,7 +37,7 @@ func ThisWeek() (time.Time, time.Time) {
|
|
|
func NextWeek() (time.Time, time.Time) {
|
|
|
_, thisEnd := ThisWeek()
|
|
|
start := thisEnd.AddDate(0, 0, 1)
|
|
|
- end := start.AddDate(0, 0, 6)
|
|
|
+ end := start.AddDate(0, 0, 6).Add(time.Hour * 23).Add(time.Minute * 59).Add(time.Second * 59)
|
|
|
return start, end
|
|
|
}
|
|
|
|
|
@@ -61,6 +61,14 @@ func ThisMonth() (time.Time, time.Time) {
|
|
|
|
|
|
// 获取下月的日期范围
|
|
|
func NextMonth() (time.Time, time.Time) {
|
|
|
- start, end := ThisMonth()
|
|
|
- return end.AddDate(0, 0, 1), start.AddDate(0, 1, 0)
|
|
|
+ now := time.Now()
|
|
|
+ year, month, _ := now.Date()
|
|
|
+ nextMonth := month + 1
|
|
|
+ if nextMonth > 12 {
|
|
|
+ nextMonth = 1
|
|
|
+ year++
|
|
|
+ }
|
|
|
+ startOfNextMonth := time.Date(year, nextMonth, 1, 0, 0, 0, 0, now.Location())
|
|
|
+ endOfNextMonth := startOfNextMonth.AddDate(0, 1, -1).Add(time.Hour*23 + time.Minute*59 + time.Second*59)
|
|
|
+ return startOfNextMonth, endOfNextMonth
|
|
|
}
|