3 Star 2 Fork 1

fotomxq/weeekj_core

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
next.go 3.59 KB
一键复制 编辑 原始数据 按行查看 历史
fotomxq 提交于 2025-02-05 18:52 +08:00 . 修改项目路径;
package CoreNextTime
import (
ToolsHolidaySeason "gitee.com/fotomxq/weeekj_core/v5/tools/holiday_season"
"github.com/golang-module/carbon"
)
// MakeNextAt 生成下一个日期
func MakeNextAt(timeType int, timeN []int64, skipHoliday bool, nextAt carbon.Carbon) (newTime carbon.Carbon, needDeleteConfig bool, b bool) {
//内部循环限制
step := 0
limit := 60
//选择日期
switch timeType {
case 0:
//每天重复
for {
if step > limit {
break
}
step += 1
nextAt = nextAt.AddDay()
//如果不是节假日,则跳出
if skipHoliday && !ToolsHolidaySeason.CheckIsWork(&ToolsHolidaySeason.ArgsCheckIsWork{
DateAt: nextAt.Time,
}) {
continue
}
break
}
case 1:
//每周重复
for {
if step > limit {
break
}
step += 1
nextAt = nextAt.AddWeek()
//如果不是节假日,则跳出
if skipHoliday && !ToolsHolidaySeason.CheckIsWork(&ToolsHolidaySeason.ArgsCheckIsWork{
DateAt: nextAt.Time,
}) {
continue
}
break
}
case 2:
//每月重复
for {
if step > limit {
break
}
step += 1
nextAt = nextAt.AddMonth()
//如果不是节假日,则跳出
if skipHoliday && !ToolsHolidaySeason.CheckIsWork(&ToolsHolidaySeason.ArgsCheckIsWork{
DateAt: nextAt.Time,
}) {
continue
}
break
}
case 3:
//临时一次
// 标记删除配置
needDeleteConfig = true
break
case 4:
//每隔N天重复
for {
if step > limit {
break
}
step += 1
if len(timeN) > 0 {
nextAt = nextAt.AddDays(int(timeN[0]))
} else {
return
}
//如果不是节假日,则跳出
if skipHoliday && !ToolsHolidaySeason.CheckIsWork(&ToolsHolidaySeason.ArgsCheckIsWork{
DateAt: nextAt.Time,
}) {
continue
}
break
}
break
case 5:
//每隔N周重复
for {
if step > limit {
break
}
step += 1
if len(timeN) > 0 {
nextAt = nextAt.AddWeeks(int(timeN[0]))
} else {
return
}
//如果不是节假日,则跳出
if skipHoliday && !ToolsHolidaySeason.CheckIsWork(&ToolsHolidaySeason.ArgsCheckIsWork{
DateAt: nextAt.Time,
}) {
continue
}
break
}
break
case 6:
//每隔N月重复
for {
if step > limit {
break
}
step += 1
if len(timeN) > 0 {
nextAt = nextAt.AddMonths(int(timeN[0]))
} else {
return
}
//如果不是节假日,则跳出
if skipHoliday && !ToolsHolidaySeason.CheckIsWork(&ToolsHolidaySeason.ArgsCheckIsWork{
DateAt: nextAt.Time,
}) {
continue
}
break
}
break
case 7:
//指定星期重复
if len(timeN) > 0 {
isOK := false
for _, vTimeN := range timeN {
//最多重复7次
step := 0
for {
step += 1
//推移一天
nextAt = nextAt.AddDay()
//如果符合,则考虑安排
if nextAt.DayOfWeek() == int(vTimeN) {
isOK = true
break
}
//如果不是节假日,则跳出
if skipHoliday && !ToolsHolidaySeason.CheckIsWork(&ToolsHolidaySeason.ArgsCheckIsWork{
DateAt: nextAt.Time,
}) {
continue
}
if step > 7 {
return
}
}
if isOK {
break
}
}
if isOK {
break
}
} else {
return
}
case 8:
//每小时重复
for {
if step > limit {
break
}
step += 1
if len(timeN) > 0 {
nextAt = nextAt.AddHours(int(timeN[0]))
} else {
break
}
//如果不是节假日,则跳出
if skipHoliday && !ToolsHolidaySeason.CheckIsWork(&ToolsHolidaySeason.ArgsCheckIsWork{
DateAt: nextAt.Time,
}) {
continue
}
break
}
default:
//无法识别,跳出
return
}
return nextAt, needDeleteConfig, true
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fotomxq/weeekj_core.git
git@gitee.com:fotomxq/weeekj_core.git
fotomxq
weeekj_core
weeekj_core
v5.4.18

搜索帮助