-
Notifications
You must be signed in to change notification settings - Fork 0
/
again.go
52 lines (44 loc) · 996 Bytes
/
again.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
46
47
48
49
50
51
52
package again
import (
"regexp"
"strconv"
"time"
)
const Name = "Again"
func DizDate(body string) ( //nolint:nonamedreturns
year int, month time.Month, day int,
) {
if body == "" {
return 0, 0, 0
}
// released on 12/10/2004
// Released on 12/10/2004
rx := regexp.MustCompile(`(?i)released on (\d\d)\/(\d\d)\/(\d\d\d\d)`)
f := rx.FindStringSubmatch(body)
const expected = 4
if len(f) != expected {
return 0, 0, 0
}
y, _ := strconv.Atoi(f[3])
m, _ := strconv.Atoi(f[2])
d, _ := strconv.Atoi(f[1])
return y, time.Month(m), d
}
func NfoDate(body string) ( //nolint:nonamedreturns
year int, month time.Month, day int,
) {
if body == "" {
return 0, 0, 0
}
// Date........: 14/09/2008
rx := regexp.MustCompile(`Date........: (\d\d)\/(\d\d)\/(\d\d\d\d)`)
f := rx.FindStringSubmatch(body)
const expected = 4
if len(f) != expected {
return 0, 0, 0
}
y, _ := strconv.Atoi(f[3])
m, _ := strconv.Atoi(f[2])
d, _ := strconv.Atoi(f[1])
return y, time.Month(m), d
}