@@ -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,45 @@ func ExactMonthDate(s rules.Strategy) rules.Rule {
3842 var dayInt = 1
3943 var exist bool
4044
41- if m .Captures [1 ] == "" && m .Captures [3 ] == "" {
45+ if m .Captures [0 ] == "" && m .Captures [2 ] == "" && m . Captures [ 4 ] == "" {
4246 return false , nil
4347 }
4448
45- if m .Captures [0 ] != "" {
46- monInt , exist = MON_WORDS [compressStr (m .Captures [0 ])]
49+ if m .Captures [2 ] != "" {
50+ monInt , exist = MON_WORDS [compressStr (m .Captures [2 ])]
4751 if ! exist {
48- mon , err := strconv .Atoi (m .Captures [0 ])
52+ mon , err := strconv .Atoi (m .Captures [2 ])
4953 if err != nil {
5054 return false , nil
5155 }
5256 monInt = mon
5357 }
5458 }
5559
56- if m .Captures [2 ] != "" {
57- dayInt , exist = DAY_WORDS [compressStr (m .Captures [2 ])]
60+ if m .Captures [4 ] != "" {
61+ dayInt , exist = DAY_WORDS [compressStr (m .Captures [4 ])]
5862 if ! exist {
59- day , err := strconv .Atoi (m .Captures [2 ])
63+ day , err := strconv .Atoi (m .Captures [4 ])
6064 if err != nil {
6165 return false , nil
6266 }
6367 dayInt = day
6468 }
6569 }
6670
71+ if m .Captures [0 ] != "" && m .Captures [1 ] != "" {
72+ mon , err := strconv .Atoi (m .Captures [0 ])
73+ if err != nil {
74+ return false , nil
75+ }
76+ day , err := strconv .Atoi (m .Captures [1 ])
77+ if err != nil {
78+ return false , nil
79+ }
80+ monInt = mon
81+ dayInt = day
82+ }
83+
6784 c .Month = & monInt
6885 c .Day = & dayInt
6986
0 commit comments