This commit is contained in:
shoopea 2019-05-09 11:13:49 +08:00
parent 1956077d86
commit 2d915156eb

13
def.go
View File

@ -101,26 +101,29 @@ 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(d, "${Day}")) log.Printf("fromChatWarsDate : Day : %s\n", r.ReplaceAllString(d, "${Day}"))
day, _ := strconv.Atoi(r.ReplaceAllString(d, "${Day}"))
log.Printf("fromChatWarsDate : Month : %s\n", r.ReplaceAllString(d, "${Month}")) log.Printf("fromChatWarsDate : Month : %s\n", r.ReplaceAllString(d, "${Month}"))
log.Printf("fromChatWarsDate : Year : %s\n", r.ReplaceAllString(d, "${Year}")) log.Printf("fromChatWarsDate : Year : %s\n", r.ReplaceAllString(d, "${Year}"))
hour, _ := strconv.Atoi(r.ReplaceAllString(d, "${Hour}"))
log.Printf("fromChatWarsDate : Hour : %s\n", r.ReplaceAllString(d, "${Hour}")) log.Printf("fromChatWarsDate : Hour : %s\n", r.ReplaceAllString(d, "${Hour}"))
hour, _ := strconv.Atoi(r.ReplaceAllString(d, "${Hour}"))
log.Printf("fromChatWarsDate : Minute : %s\n", r.ReplaceAllString(d, "${Minute}")) log.Printf("fromChatWarsDate : Minute : %s\n", r.ReplaceAllString(d, "${Minute}"))
minute, _ := strconv.Atoi(r.ReplaceAllString(d, "${Minute}"))
days := int(0) days := int(0)
for i := 1059; i < strconv.Atoi(r.ReplaceAllString(d, "${Year}")); i++ { for i := 1059; i < strconv.Atoi(r.ReplaceAllString(d, "${Year}")); i++ {
days = days + 365 days = days + 365
} }
for i := 1; i < chatWarsMonth[r.ReplaceAllString(d, "${Month}")]; i++ { for i := 1; i < chatWarsMonth[r.ReplaceAllString(d, "${Month}")]; i++ {
if _, special := chatWarsDaysSpecial[strconv.Atoi(r.ReplaceAllString(d, "${Year}"))][i]; special { if _, special := chatWarsDaysSpecial[year][i]; special {
days = days + chatWarsDaysSpecial[strconv.Atoi(r.ReplaceAllString(d, "${Year}"))][i] days = days + chatWarsDaysSpecial[year][i]
} else { } else {
days = days + chatWarsDays[i] days = days + chatWarsDays[i]
} }
} }
for i := 1; i < strconv.Atoi(r.ReplaceAllString(d, "${Day}")); i++ { for i := 1; i < day; i++ {
days++ days++
} }
hour, _ := strconv.Atoi(r.ReplaceAllString(d, "${Hour}"))
minute, _ := strconv.Atoi(r.ReplaceAllString(d, "${Minute}"))
t, _ := time.Parse(time.RFC3339, "2018-01-31T00:00:00+00:00") t, _ := time.Parse(time.RFC3339, "2018-01-31T00:00:00+00:00")
t = t.AddDate(0, 0, (days / 3)) t = t.AddDate(0, 0, (days / 3))
t = t.Add(time.Hour * ((days % 3) * 8)) t = t.Add(time.Hour * ((days % 3) * 8))