master
兔子 2 years ago
parent 0cb637b84c
commit 557abef590

@ -238,3 +238,46 @@ func TestRun(t *testing.T) {
t.FailNow() t.FailNow()
} }
} }
func TestInvalid(t *testing.T) {
exp := `[{"repeat":[{"unit":3,"value":19},{"unit":2,"value":8},{"unit":1,"value":15},{"unit":0,"value":0}],"every":false}]`
tmr := NewTimer(time.Now())
err := tmr.ImportRepeats(exp)
if err != nil {
t.Fatal(err)
}
fmt.Println(tmr.NextTimer())
}
func TestDate(t *testing.T) {
n := time.Now().Add(time.Minute)
var rp = Repeats{
Repeat: []Repeat{
{
Unit: STAR_HOUR,
Value: uint32(n.Hour()),
},
{
Unit: STAR_MINUTE,
Value: uint32(n.Minute()),
},
{
Unit: STAR_SECOND,
Value: 0,
},
},
Every: false,
}
tmr := NewTimer(time.Now(), WithRepeats(&rp))
tmr.AddTask(func() {
time.Sleep(time.Second * 2)
fmt.Println(tmr.NextTimer())
})
err := tmr.Run()
if err != nil {
t.Fatal(err)
}
fmt.Println(tmr.NextTimer())
fmt.Println(tmr.NextTimerAfterDate(time.Now().Add(time.Hour)))
time.Sleep(time.Hour)
}

@ -105,7 +105,7 @@ func (t *StarTimer) Stop() error {
} }
func (t *StarTimer) NextTimer() time.Time { func (t *StarTimer) NextTimer() time.Time {
return t.parseNextDate(t.base, true) return t.parseNextDate(time.Now(), true)
} }
func (t *StarTimer) NextTimerAfterDate(date time.Time) time.Time { func (t *StarTimer) NextTimerAfterDate(date time.Time) time.Time {

Loading…
Cancel
Save