-
Notifications
You must be signed in to change notification settings - Fork 24
/
gocal_test.go
632 lines (557 loc) · 16.5 KB
/
gocal_test.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
package gocal
import (
"fmt"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
const ics = `BEGIN:VCALENDAR
METHOD:COUNTER
BEGIN:VEVENT
DTSTART;VALUE=DATE:20141217
DTEND;VALUE=DATE:20141219
DTSTAMP:20151116T133227Z
UID:0001@example.net
CREATED:20141110T150010Z
DESCRIPTION:Amazing description on t
wo lines
LAST-MODIFIED:20141110T150010Z
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Antoin
e Popineau;X-NUM-GUESTS=0;X-RESPONSE-COMMENT="Not interested":mailto:antoi
ne.popineau@example.net
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=John
Connor;X-NUM-GUESTS=0:mailto:john.connor@example.net
LOCATION:My Place
COMMENT;LANGUAGE=en-US:I don't think so.
CLASS: PRIVATE
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Lorem Ipsum Dolor Sit Amet
TRANSP:TRANSPARENT
END:VEVENT
BEGIN:VEVENT
DTSTART:20141203T130000Z
DTEND:20141203T163000Z
DTSTAMP:20151116T133227Z
UID:0002@google.com
CREATED:20141110T145426Z
DESCRIPTION:
LAST-MODIFIED:20141110T150016Z
LOCATION:Over there
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:The quick brown fox jumps over the lazy dog
TRANSP:TRANSPARENT
X-COLOR:#abc123
X-ADDRESS:432 Main St., San Francisco
END:VEVENT`
func Test_Parse(t *testing.T) {
start, end := time.Date(2010, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2017, 1, 1, 0, 0, 0, 0, time.Local)
gc := NewParser(strings.NewReader(ics))
gc.Start, gc.End = &start, &end
err := gc.Parse()
assert.Nil(t, err)
assert.Len(t, gc.Events, 2)
assert.Equal(t, "COUNTER", gc.Method)
assert.Equal(t, "Lorem Ipsum Dolor Sit Amet", gc.Events[0].Summary)
assert.Equal(t, "PRIVATE", gc.Events[0].Class)
assert.Equal(t, "0001@example.net", gc.Events[0].Uid)
assert.Equal(t, "Amazing description on two lines", gc.Events[0].Description)
assert.Equal(t, 2, len(gc.Events[0].Attendees))
assert.Equal(t, "Antoine Popineau", gc.Events[0].Attendees[0].Cn)
assert.Equal(t, "0", gc.Events[0].Attendees[0].CustomAttributes["X-NUM-GUESTS"])
assert.Equal(t, "\"Not interested\"", gc.Events[0].Attendees[0].CustomAttributes["X-RESPONSE-COMMENT"])
assert.Equal(t, "John Connor", gc.Events[0].Attendees[1].Cn)
assert.Equal(t, 0, len(gc.Events[0].CustomAttributes))
assert.Equal(t, 2, len(gc.Events[1].CustomAttributes))
assert.Equal(t, "#abc123", gc.Events[1].CustomAttributes["X-COLOR"])
}
func Test_ParseLine(t *testing.T) {
tests := []struct {
from string
expectKey string
expectValue string
expectParams map[string]string
}{
{
from: `HELLO: world`,
expectKey: "HELLO",
expectValue: "world",
expectParams: map[string]string{},
},
{
from: `HELLO:`,
expectKey: "HELLO",
expectValue: "",
expectParams: map[string]string{},
},
{
from: `HELLO;KEY1=value1;KEY2=value2: world`,
expectKey: "HELLO",
expectValue: "world",
expectParams: map[string]string{"KEY1": `value1`, "KEY2": `value2`},
},
{
from: `HELLO;KEY1="foo:value1";KEY2="bar:value2": world`,
expectKey: "HELLO",
expectValue: "world",
expectParams: map[string]string{"KEY1": `"foo:value1"`, "KEY2": `"bar:value2"`},
},
}
for idx, test := range tests {
t.Run(fmt.Sprintf("parse-line-%d", idx), func(t *testing.T) {
gc := NewParser(strings.NewReader(test.from))
gc.scanner.Scan()
l, err, done := gc.parseLine()
assert.Equal(t, nil, err)
assert.Equal(t, true, done)
assert.Equal(t, test.expectKey, l.Key)
assert.Equal(t, test.expectValue, l.Value)
assert.Equal(t, test.expectParams, l.Params)
})
}
}
func createLine(size int) string {
return fmt.Sprintf("%s:%s", strings.Repeat("A", size), strings.Repeat("B", size))
}
func Benchmark_splitLineTokens20(b *testing.B) {
l := createLine(10)
for n := 0; n < b.N; n++ {
splitLineTokens(l)
}
}
func Benchmark_stringSplitN20(b *testing.B) {
l := createLine(10)
for n := 0; n < b.N; n++ {
strings.SplitN(l, ":", 2)
}
}
func Benchmark_splitLineTokens100(b *testing.B) {
l := createLine(50)
for n := 0; n < b.N; n++ {
splitLineTokens(l)
}
}
func Benchmark_stringSplitN100(b *testing.B) {
l := createLine(50)
for n := 0; n < b.N; n++ {
strings.SplitN(l, ":", 2)
}
}
// Event repeats every second monday and tuesday
// Instance of January, 29th is excluded
// Instance of January, 1st is changed
// Event repeats every month on the second day
const recuringICS = `BEGIN:VCALENDAR
PRODID:Gocal
VERSION:2.0
BEGIN:VEVENT
DTSTART:20180102
DTEND:20180103
DTSTAMP:20151116T133227Z
UID:0001@google.com
SUMMARY:Every month on the second
RRULE:FREQ=MONTHLY;BYMONTHDAY=2
END:VEVENT
BEGIN:VEVENT
DTSTART:20180101T090000Z
DTEND:20180101T110000Z
DTSTAMP:20151116T133227Z
UID:0002@google.com
SUMMARY:Every two weeks on mondays and tuesdays forever
RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU
EXDATE;VALUE=DATE-TIME:20180129T090000Z
END:VEVENT
BEGIN:VEVENT
DTSTART:20180101T090000Z
DTEND:20180101T110000Z
DTSTAMP:20151116T133227Z
UID:0003@google.com
SUMMARY:Every two weeks on mondays and tuesdays for three events
RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU;COUNT=3
EXDATE;VALUE=DATE-TIME:20180129T090000Z
END:VEVENT
BEGIN:VEVENT
DTSTART:20180101T110000Z
DTEND:20180101T130000Z
DTSTAMP:20151116T133227Z
UID:004@google.com
RECURRENCE-ID:20180101T090000Z
SUMMARY:This changed!
END:VEVENT
END:VCALENDAR`
func Test_ReccuringRule(t *testing.T) {
start, end := time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2018, 2, 5, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(recuringICS))
gc.Start, gc.End = &start, &end
gc.Parse()
assert.Equal(t, 11, len(gc.Events))
assert.Equal(t, "This changed!", gc.Events[0].Summary)
assert.Equal(t, "Every month on the second", gc.Events[2].Summary)
assert.Equal(t, "Every two weeks on mondays and tuesdays forever", gc.Events[4].Summary)
}
const recurringICSWithExdate = `BEGIN:VCALENDAR
BEGIN:VEVENT
UID:plop
SUMMARY:Lorem ipsum dolor sit amet
DTSTAMP:20151116T133227Z
DTSTART:20190101T130000Z
DTEND:20190101T140000Z
RRULE:FREQ=MONTHLY;COUNT=5
EXDATE:20190201T130000Z
END:VEVENT
END:VCALENDAR`
func Test_ReccuringRuleWithExdate(t *testing.T) {
start, end := time.Date(2019, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2019, 12, 31, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(recurringICSWithExdate))
gc.Start, gc.End = &start, &end
gc.Parse()
assert.Equal(t, 4, len(gc.Events))
d := time.Date(2019, 2, 1, 13, 0, 0, 0, time.Local).Format("2006-01-02")
for _, e := range gc.Events {
assert.NotEqual(t, d, e.Start.Format("2016-01-02"))
}
}
const recurringICSWithMultipleExdate = `BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Family calendar
X-WR-TIMEZONE:America/New_York
X-WR-CALDESC:Esparza family events
BEGIN:VTIMEZONE
TZID:America/Grand_Turk
X-LIC-LOCATION:America/Grand_Turk
BEGIN:STANDARD
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:America/New_York
X-LIC-LOCATION:America/New_York
BEGIN:DAYLIGHT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:America/Phoenix
X-LIC-LOCATION:America/Phoenix
BEGIN:STANDARD
TZOFFSETFROM:-0700
TZOFFSETTO:-0700
TZNAME:MST
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=America/New_York:20201220T173000
DTEND;TZID=America/New_York:20201220T183000
EXDATE;TZID=America/New_York:20210425T173000
EXDATE;TZID=America/New_York:20211024T173000
EXDATE;TZID=America/New_York:20211031T173000
EXDATE;TZID=America/New_York:20211121T173000
EXDATE;TZID=America/New_York:20211128T173000
EXDATE;TZID=America/New_York:20220220T173000
RRULE:FREQ=WEEKLY
DTSTAMP:20220220T161319Z
UID:05F28281-077F-4059-971E-40E43F8AB3B5
URL:https://us02web.zoom.us/j/9288411040?pwd=ZVZFWVNGUWc4UHVzaHRKK010dGwrdz
09
CREATED:20201220T170112Z
DESCRIPTION:
LAST-MODIFIED:20220205T221812Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Esparza family conference call 📲
TRANSP:OPAQUE
BEGIN:VALARM
ACTION:NONE
TRIGGER;VALUE=DATE-TIME:19760401T005545Z
END:VALARM
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20220218
DTEND;VALUE=DATE:20220222
DTSTAMP:20220220T161319Z
UID:6952A06D-6C4A-46D2-83DC-427A0FC5F53B
CREATED:20211021T173647Z
DESCRIPTION:
LAST-MODIFIED:20211021T173647Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Natalie’s Dress Shopping
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
`
func Test_ReccuringRuleWithMultipleExdate(t *testing.T) {
timezone := "America/New_York"
location, err := time.LoadLocation(timezone)
if err != nil {
t.Errorf("Error setting timezone: %v", err)
}
start, end := time.Date(2022, 2, 20, 0, 0, 0, 0, location), time.Date(2022, 2, 20, 23, 59, 59, 0, location)
gc := NewParser(strings.NewReader(recurringICSWithMultipleExdate))
gc.Start, gc.End = &start, &end
gc.Parse()
assert.Equal(t, 1, len(gc.Events))
}
const unknownICS = `BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART;VALUE=DATE:20180117
DTEND;VALUE=DATE:20180119
DTSTAMP:20151116T133227Z
UID:0001@example.net
CREATED:20141110T150010Z
DESCRIPTION:Amazing description on t
wo lines
LAST-MODIFIED:20141110T150010Z
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Antoin
e Popineau;X-NUM-GUESTS=0:mailto:antoine.popineau@example.net
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=John
Connor;X-NUM-GUESTS=0:mailto:john.connor@example.net
BEGIN:SOMETHING
UID:0001@example.net
BEGIN:NESTED
BEGIN:AGAINNESTED
UID:0001@example.net
END:AGAINNESTED
END:NESTED
END:SOMETHING
LOCATION:My Place
SEQUENCE:0
STATUS:CONFIRMED
BEGIN:HELLOWORLD
END:HELLOWORLD
SUMMARY:Lorem Ipsum Dolor Sit Amet
TRANSP:TRANSPARENT
END:VEVENT`
func Test_UnknownBlocks(t *testing.T) {
start, end := time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2018, 2, 5, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(unknownICS))
gc.Start, gc.End = &start, &end
err := gc.Parse()
assert.Nil(t, err)
assert.Equal(t, 1, len(gc.Events))
assert.Equal(t, "Amazing description on two lines", gc.Events[0].Description)
assert.Equal(t, "My Place", gc.Events[0].Location)
}
const invalidICS = `BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART;TZID=Europe/Paris:20190101T090000
DTEND;TZID=Europe/Paris:20190101T110000
UID:one@gocal
SUMMARY:Invalid event without DTSTAMP
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20151116T133227Z
DTSTART;TZID=Europe/Paris:20190201T090000
DTEND;TZID=Europe/Paris:20190201T110000
UID:two@gocal
SUMMARY:Valid event
END:VEVENT
END:VCALENDAR`
func Test_InvalidEventFailFeed(t *testing.T) {
start, end := time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2020, 2, 5, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(invalidICS))
gc.Start, gc.End = &start, &end
err := gc.Parse()
assert.NotNil(t, err)
assert.Equal(t, 0, len(gc.Events))
}
func Test_InvalidEventFailEvent(t *testing.T) {
start, end := time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2020, 2, 5, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(invalidICS))
gc.Start, gc.End = &start, &end
gc.Strict = StrictParams{
Mode: StrictModeFailEvent,
}
err := gc.Parse()
assert.Nil(t, err)
assert.Equal(t, 1, len(gc.Events))
}
func Test_InvalidEventFailAttribute(t *testing.T) {
start, end := time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2020, 2, 5, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(invalidICS))
gc.Start, gc.End = &start, &end
gc.Strict = StrictParams{
Mode: StrictModeFailAttribute,
}
err := gc.Parse()
assert.Nil(t, err)
assert.Equal(t, 2, len(gc.Events))
assert.False(t, gc.Events[0].Valid)
assert.True(t, gc.Events[1].Valid)
}
const durationICS = `BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTAMP:20151116T133227Z
DURATION:P1Y5DT1H10M30S
DTSTART;TZID=Europe/Paris:20190101T090000
UID:one@gocal
SUMMARY:Event with duration instead of start/end
END:VEVENT`
func Test_DurationEvent(t *testing.T) {
start, end := time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2025, 2, 5, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(durationICS))
gc.Start, gc.End = &start, &end
err := gc.Parse()
assert.Nil(t, err)
assert.Equal(t, 1, len(gc.Events))
if len(gc.Events) == 1 {
assert.Equal(t, gc.Events[0].End.Year(), 2020)
assert.Equal(t, gc.Events[0].End.Day(), 6)
assert.Equal(t, gc.Events[0].End.Hour(), 10)
assert.Equal(t, gc.Events[0].End.Minute(), 10)
assert.Equal(t, gc.Events[0].End.Second(), 30)
}
}
const dateICS = `BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTAMP:20151116T133227Z
DTSTART;VALUE=DATE:20190101
DTEND;VALUE=DATE:20190101
UID:one@gocal
SUMMARY:Event with inclusive same day event
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20151116T133227Z
DTSTART;VALUE=DATE:20190101
DTEND;VALUE=DATE:20190103
UID:two@gocal
SUMMARY:Event with exclusive same day event
END:VEVENT`
func Test_DateEvent(t *testing.T) {
start, end := time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2025, 2, 5, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(dateICS))
gc.Start, gc.End = &start, &end
err := gc.Parse()
assert.Nil(t, err)
assert.Equal(t, 2, len(gc.Events))
if len(gc.Events) == 2 {
assert.Equal(t, gc.Events[0].End.Year(), 2019)
assert.Equal(t, gc.Events[0].End.Month(), time.January)
assert.Equal(t, gc.Events[0].End.Day(), 1)
assert.Equal(t, gc.Events[0].End.Hour(), 23)
assert.Equal(t, gc.Events[0].End.Minute(), 59)
assert.Equal(t, gc.Events[0].End.Second(), 59)
assert.Equal(t, gc.Events[1].End.Year(), 2019)
assert.Equal(t, gc.Events[1].End.Month(), time.January)
assert.Equal(t, gc.Events[1].End.Day(), 2)
assert.Equal(t, gc.Events[1].End.Hour(), 23)
assert.Equal(t, gc.Events[1].End.Minute(), 59)
assert.Equal(t, gc.Events[1].End.Second(), 59)
}
}
const dupsICS = `BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTAMP:20151116T133227Z
DTSTART;VALUE=DATE:20190101
DTEND;VALUE=DATE:20190101
UID:one@gocal
UID:two@gocal
UID:three@gocal
SUMMARY:Event with inclusive same day event
END:VEVENT`
func Test_DuplicateAttributes(t *testing.T) {
start, end := time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local), time.Date(2025, 2, 5, 23, 59, 59, 0, time.Local)
gc := NewParser(strings.NewReader(dupsICS))
gc.Start, gc.End = &start, &end
err := gc.Parse()
assert.NotNil(t, err)
gc = NewParser(strings.NewReader(dupsICS))
gc.Start, gc.End = &start, &end
gc.Strict.Mode = StrictModeFailAttribute
err = gc.Parse()
assert.Nil(t, err)
assert.Len(t, gc.Events, 1)
assert.False(t, gc.Events[0].Valid)
gc = NewParser(strings.NewReader(dupsICS))
gc.Start, gc.End = &start, &end
gc.Strict.Mode = StrictModeFailEvent
err = gc.Parse()
assert.Nil(t, err)
assert.Empty(t, gc.Events)
gc = NewParser(strings.NewReader(dupsICS))
gc.Start, gc.End = &start, &end
gc.Duplicate.Mode = DuplicateModeKeepFirst
err = gc.Parse()
assert.Nil(t, err)
assert.Len(t, gc.Events, 1)
assert.Equal(t, "one@gocal", gc.Events[0].Uid)
gc = NewParser(strings.NewReader(dupsICS))
gc.Start, gc.End = &start, &end
gc.Duplicate.Mode = DuplicateModeKeepLast
err = gc.Parse()
assert.Nil(t, err)
assert.Len(t, gc.Events, 1)
assert.Equal(t, "three@gocal", gc.Events[0].Uid)
}
const recurrenceICSwithTZID = `BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART;TZID=Europe/Moscow:20240927T190000
DTEND;TZID=Europe/Moscow:20240927T200000
SUMMARY:regular event
UID:1a4pqkardx6cdkov4mj0
SEQUENCE:2
DTSTAMP:20241023T185434Z
CREATED:20240923T130134Z
RRULE:FREQ=WEEKLY;BYDAY=FR;UNTIL=20241228T170000Z;INTERVAL=1
TRANSP:OPAQUE
LAST-MODIFIED:20240923T130312Z
CLASS:PRIVATE
END:VEVENT
BEGIN:VEVENT
DTSTART;TZID=Europe/Moscow:20241025T190000
DTEND;TZID=Europe/Moscow:20241025T200000
SUMMARY:not ordinary event
UID:1a4pqkardx6cdkov4mj0
SEQUENCE:1
DTSTAMP:20241023T185434Z
CREATED:20241018T073451Z
RECURRENCE-ID;TZID=Europe/Moscow:20241025T190000
TRANSP:OPAQUE
LAST-MODIFIED:20241018T073451Z
CLASS:PRIVATE
END:VEVENT
END:VCALENDAR`
func Test_RecirrenceICSWithTZID(t *testing.T) {
start, end := time.Date(2024, 10, 25, 0, 0, 0, 0, time.UTC), time.Date(2024, 10, 25, 23, 59, 59, 0, time.UTC)
gc := NewParser(strings.NewReader(recurrenceICSwithTZID))
gc.Start, gc.End = &start, &end
gc.Parse()
assert.Equal(t, 1, len(gc.Events))
assert.Equal(t, "not ordinary event", gc.Events[0].Summary)
start, end = time.Date(2024, 10, 18, 0, 0, 0, 0, time.UTC), time.Date(2024, 10, 18, 23, 59, 59, 0, time.UTC)
gc = NewParser(strings.NewReader(recurrenceICSwithTZID))
gc.Start, gc.End = &start, &end
gc.Parse()
assert.Equal(t, 1, len(gc.Events))
assert.Equal(t, "regular event", gc.Events[0].Summary)
}