diff --git a/when/parse.go b/when/parse.go index ac749e4..b5c1a4b 100644 --- a/when/parse.go +++ b/when/parse.go @@ -179,7 +179,7 @@ func matchPeriodPattern01(base time.Time, str string) (startimer.StarTimer, erro func matchPeroidPattern02(base time.Time, str string) (startimer.StarTimer, error) { str = transChn(str) var rpt startimer.Repeats - reg := regexp.MustCompile(`(每)?([周星期礼拜][周礼拜星期到1-6日天]+)+的?([上中下午夜早凌清晨傍晚里]+)?(\d{1,4}[个点时:]+)?(\d{1,4}[分:])?(\d{1,10}秒?)?`) + reg := regexp.MustCompile(`(每)?([周星期礼拜][周礼拜星期到1-6日天]+)+的?([上中下午夜早凌清晨傍晚里]+)?(\d{1,4}[个点时:]+)?(\d{0,4}[分半:]?钟?)?(\d{1,10}秒?钟?)?`) if reg.MatchString(str) { pts := reg.FindStringSubmatch(str) if pts[2] != "" { @@ -236,6 +236,9 @@ func matchPeroidPattern02(base time.Time, str string) (startimer.StarTimer, erro rpt.Repeat = append(rpt.Repeat, startimer.Repeat{Unit: startimer.STAR_HOUR, Value: hour}) } if pts[5] != "" { + if pts[5] == "半" { + pts[5] = "30" + } rpt.Repeat = append(rpt.Repeat, startimer.Repeat{Unit: startimer.STAR_MINUTE, Value: uint32(getNumbers(pts[5]))}) } else if hour != 0 { rpt.Repeat = append(rpt.Repeat, startimer.Repeat{Unit: startimer.STAR_MINUTE, Value: 0}) diff --git a/when/parse_test.go b/when/parse_test.go index 3e9d479..215c9a9 100644 --- a/when/parse_test.go +++ b/when/parse_test.go @@ -18,7 +18,7 @@ func TestParse(t *testing.T) { } func TestSigParse(t *testing.T) { - for _, code := range []string{"6分钟后提醒我"} { + for _, code := range []string{"每周一到周五下午10:20提醒我"} { a, _ := WhenWithPeriod(code) //fmt.Println(a.Repeats()[0]) fmt.Println(a.NextTimer(), a.RunCountLimit(), code)