aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-05-03 14:39:52 -0400
committerGrant Ammons <gammons@gmail.com>2016-05-03 14:39:52 -0400
commit82dbd4a62ac62d97a61386696d992e3400167d97 (patch)
tree49f16375ab6b3e4ff045123beb53b516aeb0eff6
parentea7732efeba8fbb987117394055c11b574fc1649 (diff)
Add agenda function
-rw-r--r--todo.go4
-rw-r--r--todolist/date_filter.go14
2 files changed, 17 insertions, 1 deletions
diff --git a/todo.go b/todo.go
index a0ba30e..707ffd2 100644
--- a/todo.go
+++ b/todo.go
@@ -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 {