-
Notifications
You must be signed in to change notification settings - Fork 24
/
types.go
177 lines (151 loc) · 3.34 KB
/
types.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package gocal
import (
"bufio"
"fmt"
"strings"
"time"
"github.com/apognu/gocal/parser"
)
const (
StrictModeFailFeed = iota
StrictModeFailAttribute
StrictModeFailEvent
)
const (
DuplicateModeFailStrict = iota
DuplicateModeKeepFirst
DuplicateModeKeepLast
)
type StrictParams struct {
Mode int
}
type DuplicateParams struct {
Mode int
}
type DuplicateAttributeError struct {
Key, Value string
}
func NewDuplicateAttribute(k, v string) DuplicateAttributeError {
return DuplicateAttributeError{Key: k, Value: v}
}
func (err DuplicateAttributeError) Error() string {
return fmt.Sprintf("duplicate attribute %s: %s", err.Key, err.Value)
}
type Gocal struct {
scanner *bufio.Scanner
Events []Event
SkipBounds bool
Strict StrictParams
Duplicate DuplicateParams
buffer *Event
Start *time.Time
End *time.Time
Method string
AllDayEventsTZ *time.Location
}
const (
ContextRoot = iota
ContextEvent
ContextUnknown
)
type Context struct {
Value int
Previous *Context
}
func (ctx *Context) Nest(value int) *Context {
return &Context{Value: value, Previous: ctx}
}
func (gc *Gocal) IsInRange(d Event) bool {
if (d.Start.Before(*gc.Start) && d.End.After(*gc.Start)) ||
(d.Start.After(*gc.Start) && d.End.Before(*gc.End)) ||
(d.Start.Before(*gc.End) && d.End.After(*gc.End)) {
return true
}
return false
}
func (gc *Gocal) IsRecurringInstanceOverriden(instance *Event) bool {
for _, e := range gc.Events {
if e.Uid == instance.Uid {
rid, _ := parser.ParseTime(e.RecurrenceID, e.RawStart.Params, parser.TimeStart, false, gc.AllDayEventsTZ)
if rid.Equal(*instance.Start) {
return true
}
}
}
return false
}
type Line struct {
Key string
Params map[string]string
Value string
}
func (l *Line) Is(key, value string) bool {
if strings.TrimSpace(l.Key) == key && strings.TrimSpace(l.Value) == value {
return true
}
return false
}
func (l *Line) IsKey(key string) bool {
return strings.TrimSpace(l.Key) == key
}
func (l *Line) IsValue(value string) bool {
return strings.TrimSpace(l.Value) == value
}
type RawDate struct {
Params map[string]string
Value string
}
type Event struct {
delayed []*Line
Uid string
Summary string
Description string
Categories []string
Start *time.Time
RawStart RawDate
End *time.Time
RawEnd RawDate
Duration *time.Duration
Stamp *time.Time
Created *time.Time
LastModified *time.Time
Location string
Geo *Geo
URL string
Status string
Organizer *Organizer
Attendees []Attendee
Attachments []Attachment
IsRecurring bool
RecurrenceID string
RecurrenceRule map[string]string
ExcludeDates []time.Time
Sequence int
CustomAttributes map[string]string
Valid bool
Comment string
Class string
}
type Geo struct {
Lat float64
Long float64
}
type Organizer struct {
Cn string
DirectoryDn string
Value string
}
type Attendee struct {
Cn string
DirectoryDn string
Status string
Value string
CustomAttributes map[string]string
}
type Attachment struct {
Encoding string
Type string
Mime string
Filename string
Value string
}