|
|
@ -201,9 +201,14 @@ func (t *StarTimer) parseNextDate(base time.Time, isMock bool) time.Time {
|
|
|
|
if len(dates) == 0 {
|
|
|
|
if len(dates) == 0 {
|
|
|
|
return time.Time{}
|
|
|
|
return time.Time{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
var bt int64
|
|
|
|
|
|
|
|
if !isMock {
|
|
|
|
|
|
|
|
bt = time.Now().UnixNano()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
bt = base.UnixNano()
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, v := range dates {
|
|
|
|
for _, v := range dates {
|
|
|
|
if v.UnixNano() > now {
|
|
|
|
if v.UnixNano() > bt {
|
|
|
|
return v
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -211,54 +216,112 @@ func (t *StarTimer) parseNextDate(base time.Time, isMock bool) time.Time {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
target := base
|
|
|
|
var targets []time.Time
|
|
|
|
if !r.Every { //固定日期
|
|
|
|
var uniqueRepeat [][]Repeat
|
|
|
|
|
|
|
|
selectMap := make(map[Unit][]Repeat)
|
|
|
|
|
|
|
|
{
|
|
|
|
for _, d := range r.Repeat {
|
|
|
|
for _, d := range r.Repeat {
|
|
|
|
switch d.Unit {
|
|
|
|
selectMap[d.Unit] = append(selectMap[d.Unit], d)
|
|
|
|
case STAR_SECOND:
|
|
|
|
}
|
|
|
|
sub := int(d.Value) - target.Second()
|
|
|
|
for key, val := range selectMap {
|
|
|
|
if sub < 0 {
|
|
|
|
if key == STAR_WEEK {
|
|
|
|
sub += 60
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target = target.Add(time.Second * time.Duration(sub))
|
|
|
|
defUnikey := make([][]Repeat, 0, 1024)
|
|
|
|
case STAR_MINUTE:
|
|
|
|
for _, vs := range val {
|
|
|
|
sub := int(d.Value) - target.Minute()
|
|
|
|
if len(uniqueRepeat) == 0 {
|
|
|
|
if sub < 0 {
|
|
|
|
defUnikey = append(defUnikey, []Repeat{vs})
|
|
|
|
sub += 60
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
for k := range uniqueRepeat {
|
|
|
|
target = target.Add(time.Minute * time.Duration(sub))
|
|
|
|
tmp := make([]Repeat, len(uniqueRepeat[k])+1)
|
|
|
|
case STAR_HOUR:
|
|
|
|
copy(tmp, append(uniqueRepeat[k], vs))
|
|
|
|
sub := int(d.Value) - target.Hour()
|
|
|
|
defUnikey = append(defUnikey, tmp)
|
|
|
|
if sub < 0 {
|
|
|
|
}
|
|
|
|
sub += 24
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
target = target.Add(time.Hour * time.Duration(sub))
|
|
|
|
|
|
|
|
case STAR_DAY:
|
|
|
|
|
|
|
|
sub := int(d.Value) - target.Day()
|
|
|
|
|
|
|
|
if sub >= 0 {
|
|
|
|
|
|
|
|
target = target.Add(time.Hour * 24 * time.Duration(sub))
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target = time.Date(target.Year(), target.Month()+1, int(d.Value), target.Hour(), target.Minute(), target.Second(), 0, target.Location())
|
|
|
|
}
|
|
|
|
case STAR_MONTH:
|
|
|
|
if len(defUnikey) > 0 {
|
|
|
|
sub := int(d.Value) - int(target.Month())
|
|
|
|
uniqueRepeat = defUnikey
|
|
|
|
if sub < 0 {
|
|
|
|
}
|
|
|
|
sub += 12
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, task := range uniqueRepeat {
|
|
|
|
|
|
|
|
sort.SliceStable(task, func(i, j int) bool {
|
|
|
|
|
|
|
|
return task[i].Unit < task[j].Unit
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
target := base
|
|
|
|
|
|
|
|
if !r.Every { //固定日期
|
|
|
|
|
|
|
|
for _, d := range task {
|
|
|
|
|
|
|
|
switch d.Unit {
|
|
|
|
|
|
|
|
case STAR_SECOND:
|
|
|
|
|
|
|
|
sub := int(d.Value) - target.Second()
|
|
|
|
|
|
|
|
if sub < 0 {
|
|
|
|
|
|
|
|
sub += 60
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
target = target.Add(time.Second * time.Duration(sub))
|
|
|
|
|
|
|
|
case STAR_MINUTE:
|
|
|
|
|
|
|
|
sub := int(d.Value) - target.Minute()
|
|
|
|
|
|
|
|
if sub < 0 {
|
|
|
|
|
|
|
|
sub += 60
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
target = target.Add(time.Minute * time.Duration(sub))
|
|
|
|
|
|
|
|
case STAR_HOUR:
|
|
|
|
|
|
|
|
sub := int(d.Value) - target.Hour()
|
|
|
|
|
|
|
|
if sub < 0 {
|
|
|
|
|
|
|
|
sub += 24
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
target = target.Add(time.Hour * time.Duration(sub))
|
|
|
|
|
|
|
|
case STAR_DAY:
|
|
|
|
|
|
|
|
sub := int(d.Value) - target.Day()
|
|
|
|
|
|
|
|
if sub >= 0 {
|
|
|
|
|
|
|
|
target = target.Add(time.Hour * 24 * time.Duration(sub))
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
target = time.Date(target.Year(), target.Month()+1, int(d.Value), target.Hour(), target.Minute(), target.Second(), 0, target.Location())
|
|
|
|
|
|
|
|
case STAR_MONTH:
|
|
|
|
|
|
|
|
sub := int(d.Value) - int(target.Month())
|
|
|
|
|
|
|
|
if sub < 0 {
|
|
|
|
|
|
|
|
sub += 12
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
target = target.AddDate(0, sub, 0)
|
|
|
|
|
|
|
|
case STAR_YEAR:
|
|
|
|
|
|
|
|
sub := int(d.Value) - int(target.Year())
|
|
|
|
|
|
|
|
if sub < 0 {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
target = target.AddDate(sub, 0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target = target.AddDate(0, sub, 0)
|
|
|
|
}
|
|
|
|
case STAR_YEAR:
|
|
|
|
}
|
|
|
|
sub := int(d.Value) - int(target.Year())
|
|
|
|
|
|
|
|
if sub < 0 {
|
|
|
|
if target == base {
|
|
|
|
return time.Date(0, 0, 0, 0, 0, 0, 0, nil)
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
targets = append(targets, target)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.SliceStable(targets, func(i, j int) bool {
|
|
|
|
|
|
|
|
return targets[i].UnixNano() < targets[j].UnixNano()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
for k, v := range targets {
|
|
|
|
|
|
|
|
if v.After(base) {
|
|
|
|
|
|
|
|
targets = targets[k:]
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if val, ok := selectMap[STAR_WEEK]; ok {
|
|
|
|
|
|
|
|
if len(targets) > 0 {
|
|
|
|
|
|
|
|
for _, week := range val {
|
|
|
|
|
|
|
|
if int(targets[0].Weekday()) == int(week.Value) {
|
|
|
|
|
|
|
|
return targets[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target = target.AddDate(sub, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return t.parseStaticNextDate(targets[0].Add(time.Hour*24), r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if target == base {
|
|
|
|
if len(targets) > 0 {
|
|
|
|
return time.Time{}
|
|
|
|
return targets[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return target
|
|
|
|
return time.Time{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *StarTimer) parseEveryNextDate(target time.Time, r *Repeats, isMock bool) []time.Time {
|
|
|
|
func (t *StarTimer) parseEveryNextDate(target time.Time, r *Repeats, isMock bool) []time.Time {
|
|
|
|