|
|
@ -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)
|
|
|
|
|
|
|
|
}
|
|
|
|