-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathobs_zone.go
60 lines (51 loc) · 1.21 KB
/
obs_zone.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
package rfc5322
import (
"errors"
"strings"
"time"
"github.com/ProtonMail/go-rfc5322/parser"
)
type obsZone struct {
location *time.Location
}
func (w *walker) EnterObsZone(ctx *parser.ObsZoneContext) {
loc := time.UTC
switch strings.ToLower(ctx.GetText()) {
case "ut":
loc = time.FixedZone(ctx.GetText(), 0)
case "utc":
loc = time.FixedZone(ctx.GetText(), 0)
case "gmt":
loc = time.FixedZone(ctx.GetText(), 0)
case "est":
loc = time.FixedZone(ctx.GetText(), -5*60*60)
case "edt":
loc = time.FixedZone(ctx.GetText(), -4*60*60)
case "cst":
loc = time.FixedZone(ctx.GetText(), -6*60*60)
case "cdt":
loc = time.FixedZone(ctx.GetText(), -5*60*60)
case "mst":
loc = time.FixedZone(ctx.GetText(), -7*60*60)
case "mdt":
loc = time.FixedZone(ctx.GetText(), -6*60*60)
case "pst":
loc = time.FixedZone(ctx.GetText(), -8*60*60)
case "pdt":
loc = time.FixedZone(ctx.GetText(), -7*60*60)
default:
w.err = errors.New("bad timezone")
}
w.enter(&obsZone{
location: loc,
})
}
func (w *walker) ExitObsZone(ctx *parser.ObsZoneContext) {
type withObsZone interface {
withObsZone(*obsZone)
}
res := w.exit().(*obsZone)
if parent, ok := w.parent().(withObsZone); ok {
parent.withObsZone(res)
}
}