Initial implementation
This commit is contained in:
37
internal/models/event.go
Normal file
37
internal/models/event.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Package models defines the core data structures for the application.
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// Event represents a calendar event.
|
||||
type Event struct {
|
||||
ID string
|
||||
Title string
|
||||
Description string
|
||||
Start time.Time
|
||||
End time.Time
|
||||
AllDay bool
|
||||
Location string
|
||||
Source EventSource
|
||||
}
|
||||
|
||||
// EventSource indicates where an event originated from.
|
||||
type EventSource string
|
||||
|
||||
const (
|
||||
SourceLocal EventSource = "local"
|
||||
SourceCalDAV EventSource = "caldav"
|
||||
)
|
||||
|
||||
// IsOnDate checks if the event occurs on the given date.
|
||||
func (e *Event) IsOnDate(date time.Time) bool {
|
||||
eventDate := e.Start.Truncate(24 * time.Hour)
|
||||
checkDate := date.Truncate(24 * time.Hour)
|
||||
|
||||
if e.AllDay {
|
||||
endDate := e.End.Truncate(24 * time.Hour)
|
||||
return !checkDate.Before(eventDate) && checkDate.Before(endDate)
|
||||
}
|
||||
|
||||
return eventDate.Equal(checkDate)
|
||||
}
|
||||
Reference in New Issue
Block a user