Skip to content

Commit

Permalink
Add {Get,Set}LastModifiedAt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bcspragu committed Dec 18, 2023
1 parent aef0a29 commit 8525f6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions components.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 14 additions & 0 deletions components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 8525f6b

Please sign in to comment.