diff --git a/ical/calendar.go b/ical/calendar.go index b4e5aed..b857f58 100644 --- a/ical/calendar.go +++ b/ical/calendar.go @@ -1,7 +1,7 @@ package ical type Calendar struct { - Items []CalendarItem + Items []CalendarEvent } func (this *Calendar) Serialize() string { diff --git a/ical/calendar_item.go b/ical/calendar_event.go similarity index 59% rename from ical/calendar_item.go rename to ical/calendar_event.go index 435d524..52c9580 100644 --- a/ical/calendar_item.go +++ b/ical/calendar_event.go @@ -4,7 +4,7 @@ import ( "time" ) -type CalendarItem struct { +type CalendarEvent struct { Id string Summary string Description string @@ -15,26 +15,26 @@ type CalendarItem struct { EndAt *time.Time } -func (this *CalendarItem) StartAtUTC() *time.Time { +func (this *CalendarEvent) StartAtUTC() *time.Time { return inUTC(this.StartAt) } -func (this *CalendarItem) EndAtUTC() *time.Time { +func (this *CalendarEvent) EndAtUTC() *time.Time { return inUTC(this.EndAt) } -func (this *CalendarItem) Serialize() string { +func (this *CalendarEvent) Serialize() string { buffer := new(strBuffer) return this.serializeWithBuffer(buffer) } -func (this *CalendarItem) ToICS() string { +func (this *CalendarEvent) ToICS() string { return this.Serialize() } -func (this *CalendarItem) serializeWithBuffer(buffer *strBuffer) string { - serializer := calItemSerializer{ - item: this, +func (this *CalendarEvent) serializeWithBuffer(buffer *strBuffer) string { + serializer := calEventSerializer{ + event: this, buffer: buffer, } return serializer.serialize() diff --git a/ical/calendar_item_test.go b/ical/calendar_event_test.go similarity index 76% rename from ical/calendar_item_test.go rename to ical/calendar_event_test.go index 537f479..f549841 100644 --- a/ical/calendar_item_test.go +++ b/ical/calendar_event_test.go @@ -7,20 +7,20 @@ import ( ) func TestStartAndEndAtUTC(t *testing.T) { - item := CalendarItem{} + event := CalendarEvent{} - if item.StartAtUTC() != nil { + if event.StartAtUTC() != nil { t.Error("StartAtUTC should have been nil") } - if item.EndAtUTC() != nil { + if event.EndAtUTC() != nil { t.Error("EndAtUTC should have been nil") } tUTC := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) - item.StartAt = &tUTC - item.EndAt = &tUTC - startTime := *(item.StartAtUTC()) - endTime := *(item.EndAtUTC()) + event.StartAt = &tUTC + event.EndAt = &tUTC + startTime := *(event.StartAtUTC()) + endTime := *(event.EndAtUTC()) if startTime != tUTC { t.Error("StartAtUTC should have been", tUTC, ", but was", startTime) @@ -35,10 +35,10 @@ func TestStartAndEndAtUTC(t *testing.T) { panic(err) } tNYK := tUTC.In(nyk) - item.StartAt = &tNYK - item.EndAt = &tNYK - startTime = *(item.StartAtUTC()) - endTime = *(item.EndAtUTC()) + event.StartAt = &tNYK + event.EndAt = &tNYK + startTime = *(event.StartAtUTC()) + endTime = *(event.EndAtUTC()) if startTime != tUTC { t.Error("StartAtUTC should have been", tUTC, ", but was", startTime) @@ -48,7 +48,7 @@ func TestStartAndEndAtUTC(t *testing.T) { } } -func TestCalendarItemSerialize(t *testing.T) { +func TestCalendarEventSerialize(t *testing.T) { ny, err := time.LoadLocation("America/New_York") if err != nil { panic(err) @@ -59,7 +59,7 @@ func TestCalendarItemSerialize(t *testing.T) { startsAt := createdAt.Add(time.Second * 2).In(ny) endsAt := createdAt.Add(time.Second * 3).In(ny) - item := CalendarItem { + event := CalendarEvent { Id: "123", CreatedAtUTC: &createdAt, ModifiedAtUTC: &modifiedAt, @@ -84,8 +84,8 @@ DESCRIPTION:Lorem\nIpsum LOCATION:Berlin\nGermany END:VEVENT` - output := item.Serialize() + output := event.Serialize() if output != strings.TrimSpace(expected) { - t.Error("Expected calendar item serialization to be:\n", expected, "\n\nbut got:\n", output) + t.Error("Expected calendar event serialization to be:\n", expected, "\n\nbut got:\n", output) } } diff --git a/ical/calendar_test.go b/ical/calendar_test.go index ca3fa96..3634de3 100644 --- a/ical/calendar_test.go +++ b/ical/calendar_test.go @@ -5,12 +5,12 @@ import ( ) func TestCalendarSerialize(t *testing.T) { - calend := new(Calendar) + calendar := new(Calendar) // test calendar w/o items expected := "BEGIN:VCALENDAR\nVERSION:2.0\nEND:VCALENDAR" - output := calend.Serialize() + output := calendar.Serialize() if output != expected { t.Error("\nExpected calendar serialization to be:\n", expected, "\n\nbut got:\n", output) @@ -18,10 +18,10 @@ func TestCalendarSerialize(t *testing.T) { // test calendar with items - calend.Items = append(calend.Items, CalendarItem{Summary: "Foo"}) + calendar.Items = append(calendar.Items, CalendarEvent{Summary: "Foo"}) expected = "BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nSUMMARY:Foo\nEND:VEVENT\nEND:VCALENDAR" - output = calend.Serialize() + output = calendar.Serialize() if output != expected { t.Error("\nExpected calendar serialization to be:\n", expected, "\n\nbut got:\n", output) diff --git a/ical/serializers.go b/ical/serializers.go index 14a32eb..12c0070 100644 --- a/ical/serializers.go +++ b/ical/serializers.go @@ -40,21 +40,21 @@ func (this *calSerializer) items() { } } -type calItemSerializer struct { - item *CalendarItem +type calEventSerializer struct { + event *CalendarEvent buffer *strBuffer } const ( - itemSerializerTimeFormat = "20060102T150405Z" + eventSerializerTimeFormat = "20060102T150405Z" ) -func (this *calItemSerializer) serialize() string { - this.serializeItem() +func (this *calEventSerializer) serialize() string { + this.serializeEvent() return strings.TrimSpace(this.buffer.String()) } -func (this *calItemSerializer) serializeItem() { +func (this *calEventSerializer) serializeEvent() { this.begin() this.uid() this.created() @@ -67,55 +67,55 @@ func (this *calItemSerializer) serializeItem() { this.end() } -func (this *calItemSerializer) begin() { +func (this *calEventSerializer) begin() { this.buffer.Write("BEGIN:VEVENT\n") } -func (this *calItemSerializer) end() { +func (this *calEventSerializer) end() { this.buffer.Write("END:VEVENT\n") } -func (this *calItemSerializer) uid() { - this.serializeStringProp("UID", this.item.Id) +func (this *calEventSerializer) uid() { + this.serializeStringProp("UID", this.event.Id) } -func (this *calItemSerializer) summary() { - this.serializeStringProp("SUMMARY", this.item.Summary) +func (this *calEventSerializer) summary() { + this.serializeStringProp("SUMMARY", this.event.Summary) } -func (this *calItemSerializer) description() { - this.serializeStringProp("DESCRIPTION", this.item.Description) +func (this *calEventSerializer) description() { + this.serializeStringProp("DESCRIPTION", this.event.Description) } -func (this *calItemSerializer) location() { - this.serializeStringProp("LOCATION", this.item.Location) +func (this *calEventSerializer) location() { + this.serializeStringProp("LOCATION", this.event.Location) } -func (this *calItemSerializer) dtstart() { - this.serializeTimeProp("DTSTART", this.item.StartAtUTC()) +func (this *calEventSerializer) dtstart() { + this.serializeTimeProp("DTSTART", this.event.StartAtUTC()) } -func (this *calItemSerializer) dtend() { - this.serializeTimeProp("DTEND", this.item.EndAtUTC()) +func (this *calEventSerializer) dtend() { + this.serializeTimeProp("DTEND", this.event.EndAtUTC()) } -func (this *calItemSerializer) created() { - this.serializeTimeProp("CREATED", this.item.CreatedAtUTC) +func (this *calEventSerializer) created() { + this.serializeTimeProp("CREATED", this.event.CreatedAtUTC) } -func (this *calItemSerializer) lastModified() { - this.serializeTimeProp("LAST-MODIFIED", this.item.ModifiedAtUTC) +func (this *calEventSerializer) lastModified() { + this.serializeTimeProp("LAST-MODIFIED", this.event.ModifiedAtUTC) } -func (this *calItemSerializer) serializeStringProp(name, value string) { +func (this *calEventSerializer) serializeStringProp(name, value string) { if value != "" { escapedValue := escapeTextType(value) this.buffer.Write("%s:%s\n", name, escapedValue) } } -func (this *calItemSerializer) serializeTimeProp(name string, value *time.Time) { +func (this *calEventSerializer) serializeTimeProp(name string, value *time.Time) { if value != nil { - this.buffer.Write("%s:%s\n", name, value.Format(itemSerializerTimeFormat)) + this.buffer.Write("%s:%s\n", name, value.Format(eventSerializerTimeFormat)) } }