mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
✏️ 修正 timer
This commit is contained in:
parent
f9ce439e56
commit
fdd1135a66
@ -22,22 +22,22 @@ func (ts *Timer) nextWakeTime() (date time.Time) {
|
||||
h := ts.Hour()
|
||||
mn := ts.Minute()
|
||||
w := ts.Week()
|
||||
unit := time.Duration(ts.Minute()-date.Minute()) * time.Minute
|
||||
var unit time.Duration
|
||||
logrus.Debugln("[timer] unit init:", unit)
|
||||
if mn >= 0 {
|
||||
switch {
|
||||
case h < 0:
|
||||
if unit <= time.Second {
|
||||
unit += time.Hour
|
||||
unit = time.Hour
|
||||
}
|
||||
case d < 0 || w < 0:
|
||||
if unit <= time.Second {
|
||||
unit += time.Hour * 24
|
||||
unit = time.Hour * 24
|
||||
}
|
||||
case d == 0 && w >= 0:
|
||||
delta := time.Hour * 24 * time.Duration(int(w)-int(date.Weekday()))
|
||||
if delta < 0 {
|
||||
delta += time.Hour * 24 * 7
|
||||
delta = time.Hour * 24 * 7
|
||||
}
|
||||
unit += delta
|
||||
case m < 0:
|
||||
|
||||
@ -9,9 +9,11 @@ import (
|
||||
|
||||
func TestNextWakeTime(t *testing.T) {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
ts := &Timer{
|
||||
En1Month4Day5Week3Hour5Min6: 0xffffff,
|
||||
}
|
||||
ts := &Timer{}
|
||||
ts.SetMonth(-1)
|
||||
ts.SetWeek(6)
|
||||
ts.SetHour(16)
|
||||
ts.SetMinute(30)
|
||||
t1 := time.Until(ts.nextWakeTime())
|
||||
if t1 < 0 {
|
||||
t.Log(t1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user