summaryrefslogtreecommitdiff
path: root/page.go
diff options
context:
space:
mode:
authorJulian Jørgensen <julian@jtle.dk>2024-05-24 23:33:49 +0200
committerJulian Jørgensen <julian@jtle.dk>2024-05-24 23:33:49 +0200
commit6cdd02af0684500b5376d4d4a08feb796fdaf889 (patch)
tree7ffb2ded2251fef175f2c0ce6dfbea978152e063 /page.go
parenteabd0e769c2bfef7a7aa748d794675d3ff7a920b (diff)
Add date stuff
Diffstat (limited to 'page.go')
-rw-r--r--page.go46
1 files changed, 34 insertions, 12 deletions
diff --git a/page.go b/page.go
index bae3e7c..b58436d 100644
--- a/page.go
+++ b/page.go
@@ -1,24 +1,29 @@
package main
+import "time"
+
type Service struct {
Db Database
}
type DateInfo struct {
- Date string
- Tomorrow string
- Yesterday string
+ Date Date
+ Tomorrow Date
+ Yesterday Date
+ IsToday bool
}
type EntryPage struct {
Entry *Entry
Detached bool
Tracking *Entry
+ DateInfo DateInfo
}
type RootPage struct {
- Entry *EntryPage
- Entries []*Entry
+ DateInfo DateInfo
+ Entry *EntryPage
+ Entries []*Entry
}
type TasksPage struct {
@@ -31,6 +36,15 @@ func NewService(db Database) *Service {
}
}
+func NewDateInfo(t time.Time) DateInfo {
+ return DateInfo{
+ Date: DateFromStd(t),
+ Tomorrow: DateFromStd(t.Add(24 * time.Hour)),
+ Yesterday: DateFromStd(t.Add(-24 * time.Hour)),
+ IsToday: DateFromStd(time.Now()) == DateFromStd(t),
+ }
+}
+
func (srv *Service) GetTasksPage() (*TasksPage, error) {
tasks, err := srv.Db.GetTasks()
if err != nil {
@@ -40,16 +54,16 @@ func (srv *Service) GetTasksPage() (*TasksPage, error) {
Tasks: tasks,
}, nil
}
-func (srv *Service) GetEntryPage(detached *Entry) (*EntryPage, error) {
+func (srv *Service) GetEntryPage(detached *Entry, dt DateInfo) (*EntryPage, error) {
tracking, err := srv.Db.GetTracking()
if err != nil {
return nil, err
}
-
page := &EntryPage{
Entry: tracking,
Detached: false,
Tracking: tracking,
+ DateInfo: dt,
}
if detached != nil {
@@ -60,18 +74,26 @@ func (srv *Service) GetEntryPage(detached *Entry) (*EntryPage, error) {
return page, nil
}
-func (srv *Service) GetRootPage() (*RootPage, error) {
- entry, err := srv.GetEntryPage(nil)
+func (srv *Service) GetRootPage(date Date) (*RootPage, error) {
+ var entry *Entry = nil
+
+ if string(date) != time.Now().Format("2006-01-02") {
+ // If not today detach
+ entry = NewEntry(date)
+ }
+
+ entryPage, err := srv.GetEntryPage(entry, NewDateInfo(date.ToStd()))
if err != nil {
return nil, err
}
- entries, err := srv.Db.GetEntries()
+ entries, err := srv.Db.QueryEntry(nil, &date)
if err != nil {
return nil, err
}
return &RootPage{
- Entry: entry,
- Entries: entries,
+ DateInfo: entryPage.DateInfo,
+ Entry: entryPage,
+ Entries: entries,
}, nil
}