Skip to content

Commit

Permalink
Merge pull request #69 from jackhopner/master
Browse files Browse the repository at this point in the history
fix format when setting all day
  • Loading branch information
arran4 authored Apr 25, 2023
2 parents 19abf92 + 40e664e commit f69e132
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@ func (event *VEvent) SetStartAt(t time.Time, props ...PropertyParameter) {
}

func (event *VEvent) SetAllDayStartAt(t time.Time, props ...PropertyParameter) {
event.SetProperty(ComponentPropertyDtStart, t.UTC().Format(icalDateFormatUtc), props...)
props = append(props, WithValue(string(ValueDataTypeDate)))
event.SetProperty(ComponentPropertyDtStart, t.Format(icalDateFormatLocal), props...)
}

func (event *VEvent) SetEndAt(t time.Time, props ...PropertyParameter) {
event.SetProperty(ComponentPropertyDtEnd, t.UTC().Format(icalTimestampFormatUtc), props...)
}

func (event *VEvent) SetAllDayEndAt(t time.Time, props ...PropertyParameter) {
event.SetProperty(ComponentPropertyDtEnd, t.UTC().Format(icalDateFormatUtc), props...)
props = append(props, WithValue(string(ValueDataTypeDate)))
event.SetProperty(ComponentPropertyDtEnd, t.Format(icalDateFormatLocal), props...)
}

// SetDuration updates the duration of an event.
Expand Down
35 changes: 35 additions & 0 deletions components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,38 @@ END:VEVENT
})
}
}

func TestSetAllDay(t *testing.T) {
date, _ := time.Parse(time.RFC822, time.RFC822)

testCases := []struct {
name string
start time.Time
end time.Time
output string
}{
{
name: "test set duration - start",
start: date,
output: `BEGIN:VEVENT
UID:test-duration
DTSTART;VALUE=DATE:20060102
DTEND;VALUE=DATE:20060103
END:VEVENT
`,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
e := NewEvent("test-duration")
e.SetAllDayStartAt(date)
e.SetAllDayEndAt(date.AddDate(0, 0, 1))

// we're not testing for encoding here so lets make the actual output line breaks == expected line breaks
text := strings.Replace(e.Serialize(), "\r\n", "\n", -1)

assert.Equal(t, tc.output, text)
})
}
}

0 comments on commit f69e132

Please sign in to comment.