-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdate_time.go
57 lines (42 loc) · 961 Bytes
/
date_time.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
package rfc5322
import (
"time"
"github.com/ProtonMail/go-rfc5322/parser"
)
type dateTime struct {
day int
month time.Month
year int
hour, min, sec int
loc *time.Location
}
func (dt *dateTime) withDay(day *day) {
dt.day = day.value
}
func (dt *dateTime) withMonth(month *month) {
dt.month = month.value
}
func (dt *dateTime) withYear(year *year) {
dt.year = year.value
}
func (dt *dateTime) withHour(hour *hour) {
dt.hour = hour.value
}
func (dt *dateTime) withMinute(minute *minute) {
dt.min = minute.value
}
func (dt *dateTime) withSecond(second *second) {
dt.sec = second.value
}
func (dt *dateTime) withZone(zone *zone) {
dt.loc = zone.location
}
func (w *walker) EnterDateTime(ctx *parser.DateTimeContext) {
w.enter(&dateTime{
loc: time.UTC,
})
}
func (w *walker) ExitDateTime(ctx *parser.DateTimeContext) {
dt := w.exit().(*dateTime)
w.res = time.Date(dt.year, dt.month, dt.day, dt.hour, dt.min, dt.sec, 0, dt.loc)
}