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()
|
h := ts.Hour()
|
||||||
mn := ts.Minute()
|
mn := ts.Minute()
|
||||||
w := ts.Week()
|
w := ts.Week()
|
||||||
unit := time.Duration(ts.Minute()-date.Minute()) * time.Minute
|
var unit time.Duration
|
||||||
logrus.Debugln("[timer] unit init:", unit)
|
logrus.Debugln("[timer] unit init:", unit)
|
||||||
if mn >= 0 {
|
if mn >= 0 {
|
||||||
switch {
|
switch {
|
||||||
case h < 0:
|
case h < 0:
|
||||||
if unit <= time.Second {
|
if unit <= time.Second {
|
||||||
unit += time.Hour
|
unit = time.Hour
|
||||||
}
|
}
|
||||||
case d < 0 || w < 0:
|
case d < 0 || w < 0:
|
||||||
if unit <= time.Second {
|
if unit <= time.Second {
|
||||||
unit += time.Hour * 24
|
unit = time.Hour * 24
|
||||||
}
|
}
|
||||||
case d == 0 && w >= 0:
|
case d == 0 && w >= 0:
|
||||||
delta := time.Hour * 24 * time.Duration(int(w)-int(date.Weekday()))
|
delta := time.Hour * 24 * time.Duration(int(w)-int(date.Weekday()))
|
||||||
if delta < 0 {
|
if delta < 0 {
|
||||||
delta += time.Hour * 24 * 7
|
delta = time.Hour * 24 * 7
|
||||||
}
|
}
|
||||||
unit += delta
|
unit += delta
|
||||||
case m < 0:
|
case m < 0:
|
||||||
|
|||||||
@ -9,9 +9,11 @@ import (
|
|||||||
|
|
||||||
func TestNextWakeTime(t *testing.T) {
|
func TestNextWakeTime(t *testing.T) {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
ts := &Timer{
|
ts := &Timer{}
|
||||||
En1Month4Day5Week3Hour5Min6: 0xffffff,
|
ts.SetMonth(-1)
|
||||||
}
|
ts.SetWeek(6)
|
||||||
|
ts.SetHour(16)
|
||||||
|
ts.SetMinute(30)
|
||||||
t1 := time.Until(ts.nextWakeTime())
|
t1 := time.Until(ts.nextWakeTime())
|
||||||
if t1 < 0 {
|
if t1 < 0 {
|
||||||
t.Log(t1)
|
t.Log(t1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user