This commit is contained in:
shoopea 2019-05-08 23:19:52 +08:00
parent b33fa50b04
commit 51f95af8a8

12
def.go
View File

@ -1,7 +1,9 @@
package main package main
import ( import (
"log"
"regexp" "regexp"
"time"
) )
type ChatWarsMessage struct { type ChatWarsMessage struct {
@ -61,11 +63,11 @@ const (
func fromChatWarsDate(d string) (t time.Time, err error) { func fromChatWarsDate(d string) (t time.Time, err error) {
r := regexp.MustCompile(`(?P<Day>[0-9]{2}) (?P<Month>(Wintar|Hornung|Lenzin|Ōstar|Winni|Brāh|Hewi|Aran|Witu|Wīndume|Herbist|Hailag)) (?P<Year>[0-9]{4})( (?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})){0,1}`) r := regexp.MustCompile(`(?P<Day>[0-9]{2}) (?P<Month>(Wintar|Hornung|Lenzin|Ōstar|Winni|Brāh|Hewi|Aran|Witu|Wīndume|Herbist|Hailag)) (?P<Year>[0-9]{4})( (?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})){0,1}`)
if r.FindStringSubmatch(d) != nil { if r.FindStringSubmatch(d) != nil {
log.Printf("fromChatWarsDate : Day : %s\n", r.ReplaceAllString(m.Text, "${Day}"), objId) log.Printf("fromChatWarsDate : Day : %s\n", r.ReplaceAllString(d, "${Day}"), objId)
log.Printf("fromChatWarsDate : Month : %s\n", r.ReplaceAllString(m.Text, "${Month}"), objId) log.Printf("fromChatWarsDate : Month : %s\n", r.ReplaceAllString(d, "${Month}"), objId)
log.Printf("fromChatWarsDate : Year : %s\n", r.ReplaceAllString(m.Text, "${Year}"), objId) log.Printf("fromChatWarsDate : Year : %s\n", r.ReplaceAllString(d, "${Year}"), objId)
log.Printf("fromChatWarsDate : Hour : %s\n", r.ReplaceAllString(m.Text, "${Hour}"), objId) log.Printf("fromChatWarsDate : Hour : %s\n", r.ReplaceAllString(d, "${Hour}"), objId)
log.Printf("fromChatWarsDate : Minute : %s\n", r.ReplaceAllString(m.Text, "${Minute}"), objId) log.Printf("fromChatWarsDate : Minute : %s\n", r.ReplaceAllString(d, "${Minute}"), objId)
return time.Now(), nil return time.Now(), nil
} else { } else {
return nil, errors.New("Wrong format") return nil, errors.New("Wrong format")