func GetWeek(time time.Time) int {
week := int(time.Weekday())
if week == 0 {
return 7
}
return week
}
func GetIsCrossDay(time time.Time) bool {
CrossDayTimeList := []int{5, 0, 0}
return time.Hour() >= CrossDayTimeList[0] &&
time.Minute() >= CrossDayTimeList[1] &&
time.Second() >= CrossDayTimeList[2]
}
func GetNextCrossDayTime(curTime time.Time) time.Time {
CrossDayTimeList := []int{5, 0, 0}
nextTime := curTime
isCrossDay := GetIsCrossDay(nextTime)
if isCrossDay == true {
nextTime = curTime.AddDate(0, 0, 1)
}
nextTime = time.Date(nextTime.Year(), nextTime.Month(), nextTime.Day(), CrossDayTimeList[0], CrossDayTimeList[1], CrossDayTimeList[2], 0, time.Local)
return nextTime
}
func GetNextCrossWeekTime(curTime time.Time) time.Time {
CrossDayTimeList := []int{5, 0, 0}
curWeek := GetWeek(curTime)
nextTime := curTime
isCrossDay := GetIsCrossDay(nextTime)
if curWeek == 1 {
if isCrossDay == true {
nextTime = curTime.AddDate(0, 0, 7-curWeek+1)
}
} else {
nextTime = curTime.AddDate(0, 0, 7-curWeek+1)
}
nextTime = time.Date(nextTime.Year(), nextTime.Month(), nextTime.Day(), CrossDayTimeList[0], CrossDayTimeList[1], CrossDayTimeList[2], 0, time.Local)
return nextTime
}
func GetNextCrossMonthTime(curTime time.Time) time.Time {
CrossDayTimeList := []int{5, 0, 0}
curDay := curTime.Day()
nextTime := curTime
isCrossDay := GetIsCrossDay(nextTime)
if curDay == 1 {
if isCrossDay == true {
nextTime = curTime.AddDate(0, 1, 0)
}
} else {
nextTime = curTime.AddDate(0, 1, -curDay+1)
}
nextTime = time.Date(nextTime.Year(), nextTime.Month(), nextTime.Day(), CrossDayTimeList[0], CrossDayTimeList[1], CrossDayTimeList[2], 0, time.Local)
return nextTime
}
func GetCrossDayIsCanRefresh(curTime time.Time, lastTime time.Time) bool {
nextTime := GetNextCrossDayTime(lastTime)
if curTime.Before(nextTime) == true {
return false
}
return true
}
func GetCrossWeekIsCanRefresh(curTime time.Time, lastTime time.Time) bool {
nextTime := GetNextCrossWeekTime(lastTime)
if curTime.Before(nextTime) == true {
return false
}
return true
}
func GetCrossMonthIsCanRefresh(curTime time.Time, lastTime time.Time) bool {
nextTime := GetNextCrossMonthTime(lastTime)
if curTime.Before(nextTime) == true {
return false
}
return true
}