Skip to content

Commit

Permalink
Merge pull request #81 from zachmann/master
Browse files Browse the repository at this point in the history
add possibility to remove VEvent from calendar by id
  • Loading branch information
arran4 authored Nov 24, 2023
2 parents acf49e9 + 1dfe73f commit 7678c37
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,12 @@ func NewEvent(uniqueId string) *VEvent {
e := &VEvent{
ComponentBase{
Properties: []IANAProperty{
{BaseProperty{IANAToken: ToText(string(ComponentPropertyUniqueId)), Value: uniqueId}},
{
BaseProperty{
IANAToken: ToText(string(ComponentPropertyUniqueId)),
Value: uniqueId,
},
},
},
},
}
Expand All @@ -425,6 +430,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 {
Expand Down

0 comments on commit 7678c37

Please sign in to comment.