@@ -19,13 +19,17 @@ func ExactMonthDate(s rules.Strategy) rules.Rule {
1919 RegExp : regexp .MustCompile ("" +
2020 "(?:\\ b|^)" + // can't use \W here due to Chinese characters
2121 "(?:" +
22- "(1[0-2]|[1-9]|" + MON_WORDS_PATTERN + ")" + "(?:\\ s*)" +
23- "(月|-|/|\\ .)" + "(?:\\ s*)" +
22+ "(1[0-2]|[1-9])" + "\\ s*" + "(?:-|/|\\ .)" + "\\ s*" + "(1[0-9]|2[0-9]|3[0-1]|[1-9])" +
23+ "|" +
24+ "(?:" +
25+ "(1[0-2]|[1-9]|" + MON_WORDS_PATTERN + ")" + "\\ s*" +
26+ "(月)" + "\\ s*" +
2427 ")?" +
2528 "(?:" +
26- "(1[0-9]|2[0-9]|3[0-1]|[1-9]|" + DAY_WORDS_PATTERN + ")" + "(?:\\ s*)" +
27- "(日|号)?" +
28- ")?" ,
29+ "(1[0-9]|2[0-9]|3[0-1]|[1-9]|" + DAY_WORDS_PATTERN + ")" + "\\ s*" +
30+ "(日|号)" +
31+ ")?" +
32+ ")" ,
2933 ),
3034
3135 Applier : func (m * rules.Match , c * rules.Context , o * rules.Options , ref time.Time ) (bool , error ) {
@@ -38,32 +42,41 @@ func ExactMonthDate(s rules.Strategy) rules.Rule {
3842 var dayInt = 1
3943 var exist bool
4044
41- if m .Captures [1 ] == "" && m .Captures [3 ] == "" {
42- return false , nil
43- }
44-
45- if m .Captures [0 ] != "" {
46- monInt , exist = MON_WORDS [compressStr (m .Captures [0 ])]
45+ if m .Captures [2 ] != "" {
46+ monInt , exist = MON_WORDS [compressStr (m .Captures [2 ])]
4747 if ! exist {
48- mon , err := strconv .Atoi (m .Captures [0 ])
48+ mon , err := strconv .Atoi (m .Captures [2 ])
4949 if err != nil {
5050 return false , nil
5151 }
5252 monInt = mon
5353 }
5454 }
5555
56- if m .Captures [2 ] != "" {
57- dayInt , exist = DAY_WORDS [compressStr (m .Captures [2 ])]
56+ if m .Captures [4 ] != "" {
57+ dayInt , exist = DAY_WORDS [compressStr (m .Captures [4 ])]
5858 if ! exist {
59- day , err := strconv .Atoi (m .Captures [2 ])
59+ day , err := strconv .Atoi (m .Captures [4 ])
6060 if err != nil {
6161 return false , nil
6262 }
6363 dayInt = day
6464 }
6565 }
6666
67+ if m .Captures [0 ] != "" && m .Captures [1 ] != "" {
68+ mon , err := strconv .Atoi (m .Captures [0 ])
69+ if err != nil {
70+ return false , nil
71+ }
72+ day , err := strconv .Atoi (m .Captures [1 ])
73+ if err != nil {
74+ return false , nil
75+ }
76+ monInt = mon
77+ dayInt = day
78+ }
79+
6780 c .Month = & monInt
6881 c .Day = & dayInt
6982
0 commit comments