From 82dbd4a62ac62d97a61386696d992e3400167d97 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Tue, 3 May 2016 14:39:52 -0400 Subject: Add agenda function --- todolist/date_filter.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'todolist') diff --git a/todolist/date_filter.go b/todolist/date_filter.go index 5e4d391..baf2b5a 100644 --- a/todolist/date_filter.go +++ b/todolist/date_filter.go @@ -19,6 +19,8 @@ func (f *DateFilter) FilterDate(input string) []Todo { r, _ := regexp.Compile(`due .*$`) match := r.FindString(input) switch { + case match == "agenda": + return f.filterAgenda(now.BeginningOfDay()) case match == "due tod" || match == "due today": return f.filterToday(now.BeginningOfDay()) case match == "due tom" || match == "due tomorrow": @@ -47,6 +49,18 @@ func (f *DateFilter) FilterDate(input string) []Todo { return f.Todos } +func (f *DateFilter) filterAgenda(pivot time.Time) []Todo { + var ret []Todo + + for _, todo := range f.Todos { + dueTime, _ := time.Parse("2006-01-02", todo.Due) + if dueTime.Before(pivot) || todo.Due == pivot.Format("2006-01-02") { + ret = append(ret, todo) + } + } + return ret +} + func (f *DateFilter) filterToday(pivot time.Time) []Todo { var ret []Todo for _, todo := range f.Todos { -- cgit v1.3