Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix format when setting all day #69

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
}