add new func

master
兔子 2 years ago
parent 1218887a1b
commit b0fd8947f0

@ -195,3 +195,24 @@ func TestParseCronMax(t *testing.T) {
*/ */
} }
func TestPrepareCron2(t *testing.T) {
tk := StarTimer{
base: time.Now(),
repeat: []*Repeats{
{
Every: false,
Repeat: []Repeat{
//{Unit: STAR_MINUTE, Value: 0},
{Unit: STAR_HOUR, Value: 11},
{Unit: STAR_WEEK, Value: 5}, {Unit: STAR_WEEK, Value: 6}, {Unit: STAR_WEEK, Value: 0},
},
},
},
}
base := tk.base
for i := 0; i < 10; i++ {
base = tk.parseNextDate(base, true)
fmt.Println(base)
}
}

@ -318,10 +318,13 @@ func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats, recall bool)
} }
} }
} }
if target.UnixNano() == base.UnixNano() && veryDay == veryMonth && veryDay == 0 {
target = target.Add(time.Hour * 24)
}
if (veryDay != 0 && target.Day() != veryDay) || (veryMonth != 0 && int(target.Month()) != veryMonth) { if (veryDay != 0 && target.Day() != veryDay) || (veryMonth != 0 && int(target.Month()) != veryMonth) {
continue continue
} }
if target == base && !recall { if target.UnixNano() == base.UnixNano() && !recall {
continue continue
} }
targets = append(targets, target) targets = append(targets, target)
@ -343,8 +346,12 @@ func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats, recall bool)
return targets[0] return targets[0]
} }
} }
nextBase := time.Date(targets[0].Year(), targets[0].Month(), targets[0].Day(), 0, 0, 0, 0, targets[0].Location()) nextBase := targets[0]
return t.parseStaticNextDate(nextBase.Add(time.Hour*24), r, true) if nextBase == base {
nextBase = time.Date(targets[0].Year(), targets[0].Month(), targets[0].Day(), 0, 0, 0, 0, targets[0].Location())
nextBase = nextBase.Add(time.Hour * 24)
}
return t.parseStaticNextDate(nextBase, r, true)
} }
} }
if len(targets) > 0 { if len(targets) > 0 {

Loading…
Cancel
Save