From 4ff7bd6ba7b2b5bc2a9f929645a0225dff3b4dd1 Mon Sep 17 00:00:00 2001 From: starainrt Date: Thu, 15 Jun 2023 23:03:42 +0800 Subject: [PATCH] bug fix --- when/parse.go | 6 +++--- when/parse_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/when/parse.go b/when/parse.go index 15695e8..11a27c5 100644 --- a/when/parse.go +++ b/when/parse.go @@ -13,7 +13,7 @@ func matchPeriodPattern01(base time.Time, str string) (startimer.StarTimer, erro str = transChn(str) var rpt startimer.Repeats 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{0,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) { pts := reg.FindStringSubmatch(str) setAsDate := false @@ -129,7 +129,7 @@ func matchPeriodPattern01(base time.Time, str string) (startimer.StarTimer, erro } else { base.Add(tmodel * time.Duration(uint32(getNumbers(pts[7])))) } - } else if hour != 0 { + } else if hour != 0 || pts[5] != "" { if rpt.Every == setAsDate { rpt.Repeat = append(rpt.Repeat, startimer.Repeat{Unit: startimer.STAR_MINUTE, Value: 0}) } @@ -146,7 +146,7 @@ func matchPeriodPattern01(base time.Time, str string) (startimer.StarTimer, erro } else { base.Add(time.Second * time.Duration(uint32(getNumbers(pts[8])))) } - } else if hour != 0 || pts[7] != "" { + } else if hour != 0 || pts[5] != "" || pts[7] != "" { if rpt.Every == setAsDate { rpt.Repeat = append(rpt.Repeat, startimer.Repeat{Unit: startimer.STAR_SECOND, Value: 0}) } diff --git a/when/parse_test.go b/when/parse_test.go index 2bf3f82..d1f82c0 100644 --- a/when/parse_test.go +++ b/when/parse_test.go @@ -10,7 +10,7 @@ func TestParse(t *testing.T) { for k, code := range []string{"一个小时后告诉我事情", "三个小时后爱我", "每两个小时提醒我吃饭", "每五个月零二十五天三小时25分15秒告诉我时间", "5月23日上午3点24分12秒打我", "周五上午11点提醒我", "5时25分提醒我", "每周一到周五上午8点提醒我吃饭", "每天晚上8点提醒我吃饭", "每月16号晚上8点提醒我吃饭", "晚上8:30提醒我", - "晚上八点半提醒我", "6分钟后提醒我", "凌晨0点半", "每20秒提醒我", "半小时后提醒我", "半分钟后提醒我", "一分半后提醒我"} { + "晚上八点半提醒我", "6分钟后提醒我", "凌晨0点半", "每20秒提醒我", "半小时后提醒我", "半分钟后提醒我", "一分半后提醒我", "00:00提醒我", "凌晨零点提醒我"} { a, _ := WhenWithPeriod(code) //fmt.Println(a.Repeats()[0]) fmt.Println(a.NextTimer(), a.RunCountLimit(), code, k) @@ -19,7 +19,7 @@ func TestParse(t *testing.T) { } func TestSigParse(t *testing.T) { - for _, code := range []string{"每20秒提醒我"} { + for _, code := range []string{"凌晨零点提醒我"} { a, _ := WhenWithPeriod(code) //fmt.Println(a.Repeats()[0]) fmt.Println(a.NextTimer(), a.RunCountLimit(), code)