Skip to content

Commit

Permalink
Reintegration of #67
Browse files Browse the repository at this point in the history
  • Loading branch information
arran4 committed Sep 28, 2024
1 parent 0c815e1 commit 284ee76
Showing 1 changed file with 3 additions and 42 deletions.
45 changes: 3 additions & 42 deletions components.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,9 @@ func (cb *ComponentBase) SetDuration(d time.Duration) error {
}
return errors.New("start or end not yet defined")
}
// SetDuration updates the duration of an event.
// This function will set either the end or start time of an event depending what is already given.
// The duration defines the length of a event relative to start or end time.
//
// Notice: It will not set the DURATION key of the ics - only DTSTART and DTEND will be affected.
func (event *VEvent) SetDuration(d time.Duration) error {
t, err := event.GetStartAt()
if err == nil {
event.SetEndAt(t.Add(d))
return nil
} else {
t, err = event.GetEndAt()
if err == nil {
event.SetStartAt(t.Add(-d))
return nil
}
}
return errors.New("start or end not yet defined")

func (cb *ComponentBase) GetEndAt() (time.Time, error) {
return cb.getTimeProp(ComponentPropertyDtEnd, false)
}

func (cb *ComponentBase) getTimeProp(componentProperty ComponentProperty, expectAllDay bool) (time.Time, error) {
Expand Down Expand Up @@ -546,26 +531,6 @@ func (event *VEvent) SetResources(r string, props ...PropertyParameter) {
event.setResources(r, props...)
}

// SetDuration updates the duration of an event.
// This function will set either the end or start time of an event depending what is already given.
// The duration defines the length of a event relative to start or end time.
//
// Notice: It will not set the DURATION key of the ics - only DTSTART and DTEND will be affected.
func (event *VEvent) SetDuration(d time.Duration) error {
t, err := event.GetStartAt()
if err == nil {
event.SetEndAt(t.Add(d))
return nil
} else {
t, err = event.GetEndAt()
if err == nil {
event.SetStartAt(t.Add(-d))
return nil
}
}
return errors.New("start or end not yet defined")
}

func (event *VEvent) AddAlarm() *VAlarm {
return event.addAlarm()
}
Expand All @@ -578,10 +543,6 @@ func (event *VEvent) Alarms() (r []*VAlarm) {
return event.alarms()
}

func (event *VEvent) GetEndAt() (time.Time, error) {
return event.getTimeProp(ComponentPropertyDtEnd, false)
}

func (event *VEvent) GetAllDayEndAt() (time.Time, error) {
return event.getTimeProp(ComponentPropertyDtEnd, true)
}
Expand Down

0 comments on commit 284ee76

Please sign in to comment.