-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmonth.go
62 lines (53 loc) · 931 Bytes
/
month.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
53
54
55
56
57
58
59
60
61
62
package rfc5322
import (
"errors"
"strings"
"time"
"github.com/ProtonMail/go-rfc5322/parser"
)
type month struct {
value time.Month
}
func (w *walker) EnterMonth(ctx *parser.MonthContext) {
var m time.Month
switch strings.ToLower(ctx.GetText()) {
case "jan":
m = time.January
case "feb":
m = time.February
case "mar":
m = time.March
case "apr":
m = time.April
case "may":
m = time.May
case "jun":
m = time.June
case "jul":
m = time.July
case "aug":
m = time.August
case "sep":
m = time.September
case "oct":
m = time.October
case "nov":
m = time.November
case "dec":
m = time.December
default:
w.err = errors.New("no such month")
}
w.enter(&month{
value: m,
})
}
func (w *walker) ExitMonth(ctx *parser.MonthContext) {
type withMonth interface {
withMonth(*month)
}
res := w.exit().(*month)
if parent, ok := w.parent().(withMonth); ok {
parent.withMonth(res)
}
}