GetFilledTimer 获得填充好的ts
(dateStrs []string, botqq, grp int64, matchDateOnly bool)
| 41 | |
| 42 | // GetFilledTimer 获得填充好的ts |
| 43 | func GetFilledTimer(dateStrs []string, botqq, grp int64, matchDateOnly bool) *Timer { |
| 44 | monthStr := []rune(dateStrs[1]) |
| 45 | dayWeekStr := []rune(dateStrs[2]) |
| 46 | hourStr := []rune(dateStrs[3]) |
| 47 | minuteStr := []rune(dateStrs[4]) |
| 48 | |
| 49 | var t Timer |
| 50 | mon := time.Month(chineseNum2Int(monthStr)) |
| 51 | if (mon != -1 && mon <= 0) || mon > 12 { // 月份非法 |
| 52 | t.Alert = "月份非法!" |
| 53 | return &t |
| 54 | } |
| 55 | t.SetMonth(mon) |
| 56 | lenOfDW := len(dayWeekStr) |
| 57 | switch { |
| 58 | case lenOfDW == 4: // 包括末尾的"日" |
| 59 | dayWeekStr = []rune{dayWeekStr[0], dayWeekStr[2]} // 去除中间的十 |
| 60 | d := chineseNum2Int(dayWeekStr) |
| 61 | if (d != -1 && d <= 0) || d > 31 { // 日期非法 |
| 62 | t.Alert = "日期非法1!" |
| 63 | return &t |
| 64 | } |
| 65 | t.SetDay(d) |
| 66 | case dayWeekStr[lenOfDW-1] == rune('日'): // xx日 |
| 67 | dayWeekStr = dayWeekStr[:lenOfDW-1] |
| 68 | d := chineseNum2Int(dayWeekStr) |
| 69 | if (d != -1 && d <= 0) || d > 31 { // 日期非法 |
| 70 | t.Alert = "日期非法2!" |
| 71 | return &t |
| 72 | } |
| 73 | t.SetDay(d) |
| 74 | case dayWeekStr[0] == rune('每'): // 每周 |
| 75 | t.SetWeek(-1) |
| 76 | default: // 周x |
| 77 | w := chineseNum2Int(dayWeekStr[1:]) |
| 78 | if w == 7 { // 周天是0 |
| 79 | w = 0 |
| 80 | } |
| 81 | if w < 0 || w > 6 { // 星期非法 |
| 82 | t.Alert = "星期非法!" |
| 83 | return &t |
| 84 | } |
| 85 | t.SetWeek(time.Weekday(w)) |
| 86 | } |
| 87 | if len(hourStr) == 3 { |
| 88 | hourStr = []rune{hourStr[0], hourStr[2]} // 去除中间的十 |
| 89 | } |
| 90 | h := chineseNum2Int(hourStr) |
| 91 | if h < -1 || h > 23 { // 小时非法 |
| 92 | t.Alert = "小时非法!" |
| 93 | return &t |
| 94 | } |
| 95 | t.SetHour(h) |
| 96 | if len(minuteStr) == 3 { |
| 97 | minuteStr = []rune{minuteStr[0], minuteStr[2]} // 去除中间的十 |
| 98 | } |
| 99 | minute := chineseNum2Int(minuteStr) |
| 100 | if minute < -1 || minute > 59 { // 分钟非法 |