| 16 | } |
| 17 | |
| 18 | func (t *Timer) nextWakeTime() (date time.Time) { |
| 19 | date = time.Now() |
| 20 | m := t.Month() |
| 21 | d := t.Day() |
| 22 | h := t.Hour() |
| 23 | mn := t.Minute() |
| 24 | w := t.Week() |
| 25 | var unit time.Duration |
| 26 | logrus.Debugln("[timer] unit init:", unit) |
| 27 | if mn >= 0 { |
| 28 | switch { |
| 29 | case h < 0: |
| 30 | if unit <= time.Second { |
| 31 | unit = time.Hour |
| 32 | } |
| 33 | case d < 0 || w < 0: |
| 34 | if unit <= time.Second { |
| 35 | unit = time.Hour * 24 |
| 36 | } |
| 37 | case d == 0 && w >= 0: |
| 38 | delta := time.Hour * 24 * time.Duration(int(w)-int(date.Weekday())) |
| 39 | if delta < 0 { |
| 40 | delta = time.Hour * 24 * 7 |
| 41 | } |
| 42 | unit += delta |
| 43 | case m < 0: |
| 44 | unit = -1 |
| 45 | } |
| 46 | } else { |
| 47 | unit = time.Minute |
| 48 | } |
| 49 | logrus.Debugln("[timer] unit:", unit) |
| 50 | stable := 0 |
| 51 | if mn < 0 { |
| 52 | mn = date.Minute() |
| 53 | } |
| 54 | if h < 0 { |
| 55 | h = date.Hour() |
| 56 | } else { |
| 57 | stable |= 0x8 |
| 58 | } |
| 59 | switch { |
| 60 | case d < 0: |
| 61 | d = date.Day() |
| 62 | case d > 0: |
| 63 | stable |= 0x4 |
| 64 | default: |
| 65 | d = date.Day() |
| 66 | if w >= 0 { |
| 67 | stable |= 0x2 |
| 68 | } |
| 69 | } |
| 70 | if m < 0 { |
| 71 | m = date.Month() |
| 72 | } else { |
| 73 | stable |= 0x1 |
| 74 | } |
| 75 | switch stable { |