-
Notifications
You must be signed in to change notification settings - Fork 0
/
arcade.go
45 lines (39 loc) · 890 Bytes
/
arcade.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package arcade
import (
"regexp"
"strconv"
"time"
"github.com/Defacto2/df2/pkg/str"
)
const Name = "Arcade"
func NfoDate(body string) ( //nolint:nonamedreturns
year int, month time.Month, day int,
) {
if body == "" {
return 0, 0, 0
}
// DATE ......: 02/2011
// Date..: 12/2009
// Date.: 12/2008
rx := regexp.MustCompile(`(?i)DATE[ ]{0,}[.]{1,}: (\d?\d)\/(\d\d\d\d)`)
f := rx.FindStringSubmatch(body)
const mmyyyy = 3
if len(f) == mmyyyy {
y, _ := strconv.Atoi(f[2])
m, _ := strconv.Atoi(f[1])
d := 0
return y, time.Month(m), d
}
// Date.: 05.01.06
// DATE: 08.31.04
rx = regexp.MustCompile(`(?i)Date[.]{0,}:[ ]{1,}(\d\d)\.(\d\d)\.(\d\d)`)
f = rx.FindStringSubmatch(body)
const ddmmyy = 4
if len(f) == ddmmyy {
y := str.YearAbbr(f[3])
m, _ := strconv.Atoi(f[1])
d, _ := strconv.Atoi(f[2])
return y, time.Month(m), d
}
return 0, 0, 0
}