diff options
| author | Grant Ammons <gammons@gmail.com> | 2017-07-11 05:45:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-11 05:45:21 -0400 |
| commit | 024696b7751757d74096214d22a0bf013a9c881f (patch) | |
| tree | d8745ee7d76b5124ca1a26736a9e9165d17d226d | |
| parent | dafb74428d8a16b28533aa25f83f25ea255c18a3 (diff) | |
| parent | df7cfd99feda5cf702790419b95a1bab59e50937 (diff) | |
Merge pull request #73 from NonerKao/master
Fix #65, filtering out completed todos in agenda mode
| -rw-r--r-- | todolist/date_filter.go | 2 | ||||
| -rw-r--r-- | todolist/date_filter_test.go | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/todolist/date_filter.go b/todolist/date_filter.go index fb06682..8d64484 100644 --- a/todolist/date_filter.go +++ b/todolist/date_filter.go @@ -57,7 +57,7 @@ func (f *DateFilter) filterAgenda(pivot time.Time) []*Todo { var ret []*Todo for _, todo := range f.Todos { - if todo.Due == "" { + if todo.Due == "" || todo.Completed { continue } dueTime, _ := time.ParseInLocation("2006-01-02", todo.Due, f.Location) diff --git a/todolist/date_filter_test.go b/todolist/date_filter_test.go index 444b4ac..6dd88f6 100644 --- a/todolist/date_filter_test.go +++ b/todolist/date_filter_test.go @@ -96,3 +96,22 @@ func TestFilterDay(t *testing.T) { assert.Equal(1, len(filtered)) assert.Equal(1, filtered[0].Id) } + +func TestFilterAgenda(t *testing.T) { + assert := assert.New(t) + + var todos []*Todo + + completedTodo := &Todo{Id: 1, Subject: "completed", Completed: true, Due: time.Now().Format("2006-01-02")} + uncompletedTodo := &Todo{Id: 2, Subject: "uncompleted", Due: time.Now().Format("2006-01-02")} + + todos = append(todos, completedTodo) + todos = append(todos, uncompletedTodo) + + filter := NewDateFilter(todos) + + filtered := filter.filterAgenda(time.Now()) + + assert.Equal(1, len(filtered)) + assert.Equal(2, filtered[0].Id) +} |
