From 8525f6ba7d7e11e6b28c81f61d44bb80ab49603f Mon Sep 17 00:00:00 2001 From: Brandon Sprague Date: Mon, 18 Dec 2023 08:44:45 -0800 Subject: [PATCH] Add {Get,Set}LastModifiedAt Adding some helpers for parsing another timestamp field. I originally considered exposing `getTimeProp` as `ParseTimeProp`, but the ergonomics are weird enough (is the prop nil? should it be all-day-able?) that I decided against it. --- components.go | 8 ++++++++ components_test.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/components.go b/components.go index f7dc05f..2914a69 100644 --- a/components.go +++ b/components.go @@ -139,6 +139,10 @@ func (event *VEvent) SetAllDayEndAt(t time.Time, props ...PropertyParameter) { event.SetProperty(ComponentPropertyDtEnd, t.Format(icalDateFormatLocal), props...) } +func (event *VEvent) SetLastModifiedAt(t time.Time, props ...PropertyParameter) { + event.SetProperty(ComponentPropertyLastModified, t.UTC().Format(icalTimestampFormatUtc), 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. @@ -234,6 +238,10 @@ func (event *VEvent) GetEndAt() (time.Time, error) { return event.getTimeProp(ComponentPropertyDtEnd, false) } +func (event *VEvent) GetLastModifiedAt() (time.Time, error) { + return event.getTimeProp(ComponentPropertyLastModified, false) +} + func (event *VEvent) GetAllDayStartAt() (time.Time, error) { return event.getTimeProp(ComponentPropertyDtStart, true) } diff --git a/components_test.go b/components_test.go index d7d8902..d42a83e 100644 --- a/components_test.go +++ b/components_test.go @@ -94,3 +94,17 @@ END:VEVENT }) } } + +func TestGetLastModifiedAt(t *testing.T) { + e := NewEvent("test-last-modified") + lastModified := time.Unix(123456789, 0) + e.SetLastModifiedAt(lastModified) + got, err := e.GetLastModifiedAt() + if err != nil { + t.Fatalf("e.GetLastModifiedAt: %v", err) + } + + if !got.Equal(lastModified) { + t.Errorf("got last modified = %q, want %q", got, lastModified) + } +}