diff options
| -rw-r--r-- | todo.go | 4 | ||||
| -rw-r--r-- | todolist/date_filter.go | 14 |
2 files changed, 17 insertions, 1 deletions
@@ -42,7 +42,7 @@ func usage() { blueBold.Println("\nListing todos") fmt.Println(" When listing todos, you can filter and group the output.\n") - fmt.Println(" todo l due (tod|today|tom|tomorrow|overdue|this week|next week|mon|tue|wed|thu|fri|sat|sun)") + fmt.Println(" todo l due (agenda|tod|today|tom|tomorrow|overdue|this week|next week|mon|tue|wed|thu|fri|sat|sun)") fmt.Println(" todo l overdue") cyan.Println(" Filtering by date:\n") @@ -54,6 +54,8 @@ func usage() { fmt.Println("\tlists all todos due monday\n") yellow.Println("\ttodo l overdue") fmt.Println("\tlists all todos where the due date is in the past\n") + yellow.Println("\ttodo l agenda") + fmt.Println("\tlists all todos where the due date is today or in the past\n") cyan.Println(" Grouping:") fmt.Println(" You can group todos by context or project.") 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 { |
