1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package models
import "time"
type TimelineItemType string
const (
TimelineItemTypeTask TimelineItemType = "task"
TimelineItemTypeMeal TimelineItemType = "meal"
TimelineItemTypeCard TimelineItemType = "card"
TimelineItemTypeEvent TimelineItemType = "event"
)
type DaySection string
const (
DaySectionToday DaySection = "today"
DaySectionTomorrow DaySection = "tomorrow"
DaySectionLater DaySection = "later"
)
type TimelineItem struct {
ID string `json:"id"`
Type TimelineItemType `json:"type"`
Title string `json:"title"`
Time time.Time `json:"time"`
EndTime *time.Time `json:"end_time,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
OriginalItem interface{} `json:"-"`
// UI enhancement fields
IsCompleted bool `json:"is_completed"`
DaySection DaySection `json:"day_section"`
Source string `json:"source"` // "todoist", "trello", "plantoeat", "calendar"
}
// ComputeDaySection sets the DaySection based on the item's time
func (item *TimelineItem) ComputeDaySection(now time.Time) {
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
tomorrow := today.AddDate(0, 0, 1)
dayAfterTomorrow := today.AddDate(0, 0, 2)
itemDay := time.Date(item.Time.Year(), item.Time.Month(), item.Time.Day(), 0, 0, 0, 0, item.Time.Location())
if itemDay.Before(tomorrow) {
item.DaySection = DaySectionToday
} else if itemDay.Before(dayAfterTomorrow) {
item.DaySection = DaySectionTomorrow
} else {
item.DaySection = DaySectionLater
}
}
|