From 02c63354dc7614411c44eb466822dd5744cc73b2 Mon Sep 17 00:00:00 2001 From: zachmann Date: Thu, 11 Apr 2024 06:36:19 +0200 Subject: [PATCH] Re-add Calendar.RemoveEvent method --- components.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components.go b/components.go index 71d4e96..3931825 100644 --- a/components.go +++ b/components.go @@ -413,6 +413,22 @@ func (calendar *Calendar) AddVEvent(e *VEvent) { calendar.Components = append(calendar.Components, e) } +func (calendar *Calendar) RemoveEvent(id string) { + for i := range calendar.Components { + switch event := calendar.Components[i].(type) { + case *VEvent: + if event.Id() == id { + if len(calendar.Components) > i+1 { + calendar.Components = append(calendar.Components[:i], calendar.Components[i+1:]...) + } else { + calendar.Components = calendar.Components[:i] + } + return + } + } + } +} + func (calendar *Calendar) Events() (r []*VEvent) { r = []*VEvent{} for i := range calendar.Components {