|
|
@ -134,6 +134,9 @@ func (t *StarTimer) ImportRepeats(r string) error {
|
|
|
|
func (t *StarTimer) BaseDate() time.Time {
|
|
|
|
func (t *StarTimer) BaseDate() time.Time {
|
|
|
|
return t.base
|
|
|
|
return t.base
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *StarTimer) SetBaseDate(date time.Time) {
|
|
|
|
|
|
|
|
t.base = date
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *StarTimer) ResetWithRepeat(base time.Time, repeat []*Repeats) error {
|
|
|
|
func (t *StarTimer) ResetWithRepeat(base time.Time, repeat []*Repeats) error {
|
|
|
|
t.Stop()
|
|
|
|
t.Stop()
|
|
|
@ -142,6 +145,10 @@ func (t *StarTimer) ResetWithRepeat(base time.Time, repeat []*Repeats) error {
|
|
|
|
return t.Run()
|
|
|
|
return t.Run()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (t *StarTimer) Repeats() []*Repeats {
|
|
|
|
|
|
|
|
return t.repeat
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *StarTimer) Run() error {
|
|
|
|
func (t *StarTimer) Run() error {
|
|
|
|
t.mu.Lock()
|
|
|
|
t.mu.Lock()
|
|
|
|
defer t.mu.Unlock()
|
|
|
|
defer t.mu.Unlock()
|
|
|
@ -192,7 +199,7 @@ func (t *StarTimer) parseNextDate(base time.Time, isMock bool) time.Time {
|
|
|
|
if d.Every {
|
|
|
|
if d.Every {
|
|
|
|
dates = append(dates, t.parseEveryNextDate(base, d, isMock)...)
|
|
|
|
dates = append(dates, t.parseEveryNextDate(base, d, isMock)...)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
dates = append(dates, t.parseStaticNextDate(base, d))
|
|
|
|
dates = append(dates, t.parseStaticNextDate(base, d, false))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.SliceStable(dates, func(i, j int) bool {
|
|
|
|
sort.SliceStable(dates, func(i, j int) bool {
|
|
|
@ -215,7 +222,8 @@ func (t *StarTimer) parseNextDate(base time.Time, isMock bool) time.Time {
|
|
|
|
return time.Time{}
|
|
|
|
return time.Time{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats, recall bool) time.Time {
|
|
|
|
|
|
|
|
base = time.Date(base.Year(), base.Month(), base.Day(), base.Hour(), base.Minute(), base.Second(), 0, base.Location())
|
|
|
|
var targets []time.Time
|
|
|
|
var targets []time.Time
|
|
|
|
var uniqueRepeat [][]Repeat
|
|
|
|
var uniqueRepeat [][]Repeat
|
|
|
|
selectMap := make(map[Unit][]Repeat)
|
|
|
|
selectMap := make(map[Unit][]Repeat)
|
|
|
@ -249,6 +257,7 @@ func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
return task[i].Unit < task[j].Unit
|
|
|
|
return task[i].Unit < task[j].Unit
|
|
|
|
})
|
|
|
|
})
|
|
|
|
target := base
|
|
|
|
target := base
|
|
|
|
|
|
|
|
veryDay, veryMonth := 0, 0 //验证日期
|
|
|
|
if !r.Every { //固定日期
|
|
|
|
if !r.Every { //固定日期
|
|
|
|
for _, d := range task {
|
|
|
|
for _, d := range task {
|
|
|
|
switch d.Unit {
|
|
|
|
switch d.Unit {
|
|
|
@ -271,6 +280,7 @@ func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target = target.Add(time.Hour * time.Duration(sub))
|
|
|
|
target = target.Add(time.Hour * time.Duration(sub))
|
|
|
|
case STAR_DAY:
|
|
|
|
case STAR_DAY:
|
|
|
|
|
|
|
|
veryDay = int(d.Value)
|
|
|
|
sub := int(d.Value) - target.Day()
|
|
|
|
sub := int(d.Value) - target.Day()
|
|
|
|
if sub >= 0 {
|
|
|
|
if sub >= 0 {
|
|
|
|
target = target.Add(time.Hour * 24 * time.Duration(sub))
|
|
|
|
target = target.Add(time.Hour * 24 * time.Duration(sub))
|
|
|
@ -278,6 +288,7 @@ func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target = time.Date(target.Year(), target.Month()+1, int(d.Value), target.Hour(), target.Minute(), target.Second(), 0, target.Location())
|
|
|
|
target = time.Date(target.Year(), target.Month()+1, int(d.Value), target.Hour(), target.Minute(), target.Second(), 0, target.Location())
|
|
|
|
case STAR_MONTH:
|
|
|
|
case STAR_MONTH:
|
|
|
|
|
|
|
|
veryMonth = int(d.Value)
|
|
|
|
sub := int(d.Value) - int(target.Month())
|
|
|
|
sub := int(d.Value) - int(target.Month())
|
|
|
|
if sub < 0 {
|
|
|
|
if sub < 0 {
|
|
|
|
sub += 12
|
|
|
|
sub += 12
|
|
|
@ -292,8 +303,10 @@ func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (veryDay != 0 && target.Day() != veryDay) || (veryMonth != 0 && int(target.Month()) != veryMonth) {
|
|
|
|
if target == base {
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if target == base && !recall {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
targets = append(targets, target)
|
|
|
|
targets = append(targets, target)
|
|
|
@ -303,7 +316,7 @@ func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
return targets[i].UnixNano() < targets[j].UnixNano()
|
|
|
|
return targets[i].UnixNano() < targets[j].UnixNano()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
for k, v := range targets {
|
|
|
|
for k, v := range targets {
|
|
|
|
if v.After(base) {
|
|
|
|
if v.UnixNano() > base.UnixNano() || (recall && v.UnixNano() == base.UnixNano()) {
|
|
|
|
targets = targets[k:]
|
|
|
|
targets = targets[k:]
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -315,7 +328,8 @@ func (t *StarTimer) parseStaticNextDate(base time.Time, r *Repeats) time.Time {
|
|
|
|
return targets[0]
|
|
|
|
return targets[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return t.parseStaticNextDate(targets[0].Add(time.Hour*24), r)
|
|
|
|
nextBase := time.Date(targets[0].Year(), targets[0].Month(), targets[0].Day(), 0, 0, 0, 0, targets[0].Location())
|
|
|
|
|
|
|
|
return t.parseStaticNextDate(nextBase.Add(time.Hour*24), r, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(targets) > 0 {
|
|
|
|
if len(targets) > 0 {
|
|
|
|