diff options
| author | Grant Ammons <gammons@gmail.com> | 2016-05-03 14:39:52 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2016-05-03 14:39:52 -0400 |
| commit | 82dbd4a62ac62d97a61386696d992e3400167d97 (patch) | |
| tree | 49f16375ab6b3e4ff045123beb53b516aeb0eff6 /todolist | |
| parent | ea7732efeba8fbb987117394055c11b574fc1649 (diff) | |
Add agenda function
Diffstat (limited to 'todolist')
| -rw-r--r-- | todolist/date_filter.go | 14 |
1 files changed, 14 insertions, 0 deletions
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 { |
