bug fix
This commit is contained in:
parent
a0cdb02875
commit
96419e47fa
@ -77,7 +77,7 @@ func innerLoadDB(db *stardb.StarDB, callback func(task Task)) (*Remind, error) {
|
|||||||
tmr.SetRunCountLimit(int(task.Limit))
|
tmr.SetRunCountLimit(int(task.Limit))
|
||||||
task.timer = &tmr
|
task.timer = &tmr
|
||||||
task.timer.AddTask(func() {
|
task.timer.AddTask(func() {
|
||||||
rem.callbackFn(task)
|
rem.callbackFn(&task)
|
||||||
})
|
})
|
||||||
err = task.timer.Run()
|
err = task.timer.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,7 +85,7 @@ func innerLoadDB(db *stardb.StarDB, callback func(task Task)) (*Remind, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rem.tasks[task.ID] = task
|
rem.tasks[task.ID] = task
|
||||||
fmt.Printf("%+v\n", task)
|
fmt.Printf("%v %+v\n", tmr.NextTimer(), task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &rem, nil
|
return &rem, nil
|
||||||
@ -94,9 +94,9 @@ func innerLoadDB(db *stardb.StarDB, callback func(task Task)) (*Remind, error) {
|
|||||||
func (t Task) GetTimer() *startimer.StarTimer {
|
func (t Task) GetTimer() *startimer.StarTimer {
|
||||||
return t.timer
|
return t.timer
|
||||||
}
|
}
|
||||||
func (r *Remind) callbackFn(task Task) {
|
func (r *Remind) callbackFn(task *Task) {
|
||||||
if r.callback != nil {
|
if r.callback != nil {
|
||||||
r.callback(task)
|
r.callback(*task)
|
||||||
}
|
}
|
||||||
if !task.GetTimer().IsRunning() {
|
if !task.GetTimer().IsRunning() {
|
||||||
r.DeleteTask(task.ID)
|
r.DeleteTask(task.ID)
|
||||||
@ -121,7 +121,7 @@ func (r *Remind) AddTask(taskStr, key string, msg []byte) (Task, error) {
|
|||||||
Limit: int64(tmr.RunCountLimit()),
|
Limit: int64(tmr.RunCountLimit()),
|
||||||
}
|
}
|
||||||
rmt.timer.AddTask(func() {
|
rmt.timer.AddTask(func() {
|
||||||
r.callbackFn(rmt)
|
r.callbackFn(&rmt)
|
||||||
})
|
})
|
||||||
res, err := r.db.Insert(rmt, "remind", "id")
|
res, err := r.db.Insert(rmt, "remind", "id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,7 +13,7 @@ func matchPeriodPattern01(base time.Time, str string) (startimer.StarTimer, erro
|
|||||||
str = transChn(str)
|
str = transChn(str)
|
||||||
var rpt startimer.Repeats
|
var rpt startimer.Repeats
|
||||||
var duration time.Duration
|
var duration time.Duration
|
||||||
reg := regexp.MustCompile(`(每隔|每)?(\d{0,4}年)?(\d{0,5}个?月)?(\d{0,4}[明后大]{0,4}[日号天])?([上中下午夜早凌清晨傍晚里]+)?(\d{1,4}个?[点小时钟:]+)?(\d{0,4}[半分:]?[钟]?)?(\d{1,10}[秒]?[钟]?)?(后)?`)
|
reg := regexp.MustCompile(`(每隔|每)?(\d{0,4}年)?(\d{0,5}个?月)?(\d{0,4}[明后大]{0,4}[日号天])?([上中下午夜早凌清晨傍晚里]+)?(\d{1,4}个?[点小时钟:]+)?(\d{0,4}[半分:秒]?钟?)?(\d{0,10}秒?钟?)?(后)?`)
|
||||||
if reg.MatchString(str) {
|
if reg.MatchString(str) {
|
||||||
pts := reg.FindStringSubmatch(str)
|
pts := reg.FindStringSubmatch(str)
|
||||||
setAsDate := false
|
setAsDate := false
|
||||||
@ -116,12 +116,18 @@ func matchPeriodPattern01(base time.Time, str string) (startimer.StarTimer, erro
|
|||||||
if pts[7] == "半" {
|
if pts[7] == "半" {
|
||||||
pts[7] = "30"
|
pts[7] = "30"
|
||||||
}
|
}
|
||||||
|
model := startimer.STAR_MINUTE
|
||||||
|
tmodel := time.Minute
|
||||||
|
if strings.Contains(pts[7], "秒") {
|
||||||
|
model = startimer.STAR_SECOND
|
||||||
|
tmodel = time.Second
|
||||||
|
}
|
||||||
if rpt.Every == setAsDate {
|
if rpt.Every == setAsDate {
|
||||||
rpt.Repeat = append(rpt.Repeat, startimer.Repeat{Unit: startimer.STAR_MINUTE, Value: uint32(getNumbers(pts[7]))})
|
rpt.Repeat = append(rpt.Repeat, startimer.Repeat{Unit: model, Value: uint32(getNumbers(pts[7]))})
|
||||||
} else if rpt.Every && !setAsDate {
|
} else if rpt.Every && !setAsDate {
|
||||||
duration += time.Minute * time.Duration(uint32(getNumbers(pts[7])))
|
duration += tmodel * time.Duration(uint32(getNumbers(pts[7])))
|
||||||
} else {
|
} else {
|
||||||
base.Add(time.Minute * time.Duration(uint32(getNumbers(pts[7]))))
|
base.Add(tmodel * time.Duration(uint32(getNumbers(pts[7]))))
|
||||||
}
|
}
|
||||||
} else if hour != 0 {
|
} else if hour != 0 {
|
||||||
if rpt.Every == setAsDate {
|
if rpt.Every == setAsDate {
|
||||||
|
@ -7,18 +7,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestParse(t *testing.T) {
|
||||||
for _, code := range []string{"一个小时后告诉我事情", "三个小时后爱我", "每两个小时提醒我吃饭",
|
for k, code := range []string{"一个小时后告诉我事情", "三个小时后爱我", "每两个小时提醒我吃饭",
|
||||||
"每五个月零二十五天三小时25分15秒告诉我时间", "5月23日上午3点24分12秒打我", "周五上午11点提醒我", "5时25分提醒我",
|
"每五个月零二十五天三小时25分15秒告诉我时间", "5月23日上午3点24分12秒打我", "周五上午11点提醒我", "5时25分提醒我",
|
||||||
"每周一到周五上午8点提醒我吃饭", "每天晚上8点提醒我吃饭", "每月16号晚上8点提醒我吃饭", "晚上8:30提醒我", "晚上八点半提醒我", "6分钟后提醒我", "凌晨0点半"} {
|
"每周一到周五上午8点提醒我吃饭", "每天晚上8点提醒我吃饭", "每月16号晚上8点提醒我吃饭", "晚上8:30提醒我",
|
||||||
|
"晚上八点半提醒我", "6分钟后提醒我", "凌晨0点半", "每20秒提醒我"} {
|
||||||
a, _ := WhenWithPeriod(code)
|
a, _ := WhenWithPeriod(code)
|
||||||
//fmt.Println(a.Repeats()[0])
|
//fmt.Println(a.Repeats()[0])
|
||||||
fmt.Println(a.NextTimer(), a.RunCountLimit(), code)
|
fmt.Println(a.NextTimer(), a.RunCountLimit(), code, k)
|
||||||
fmt.Println(a.NextTimerAfterDate(time.Now().Add(time.Hour * 72)))
|
fmt.Println(a.NextTimerAfterDate(time.Now().Add(time.Hour * 72)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSigParse(t *testing.T) {
|
func TestSigParse(t *testing.T) {
|
||||||
for _, code := range []string{"每周一到周五下午10:20提醒我"} {
|
for _, code := range []string{"每20秒提醒我"} {
|
||||||
a, _ := WhenWithPeriod(code)
|
a, _ := WhenWithPeriod(code)
|
||||||
//fmt.Println(a.Repeats()[0])
|
//fmt.Println(a.Repeats()[0])
|
||||||
fmt.Println(a.NextTimer(), a.RunCountLimit(), code)
|
fmt.Println(a.NextTimer(), a.RunCountLimit(), code)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user