From 74df3983a089d06cc652c827fae5eca1b4cfa1b3 Mon Sep 17 00:00:00 2001 From: starainrt Date: Thu, 18 May 2023 23:47:50 +0800 Subject: [PATCH] bug fix --- when/parse.go | 5 ++++- when/parse_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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)