diff options
| author | Grant Ammons <gammons@gmail.com> | 2016-05-17 08:50:24 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2016-05-17 08:50:24 -0400 |
| commit | a37f3ca57cec1767a2e6db45254f54d80c83fdf1 (patch) | |
| tree | bb29ad7ad0035f150643a8e4533814fc3248619f | |
| parent | c8c6fea0a89d7ce0bcb74ac53681e5cd9ed63e02 (diff) | |
Promote FindSunday so we can use it in tests, fix testsvsnapshot
| -rw-r--r-- | todolist/date_filter.go | 6 | ||||
| -rw-r--r-- | todolist/date_filter_test.go | 10 |
2 files changed, 10 insertions, 6 deletions
diff --git a/todolist/date_filter.go b/todolist/date_filter.go index c3d81fd..2bf51e2 100644 --- a/todolist/date_filter.go +++ b/todolist/date_filter.go @@ -102,7 +102,7 @@ func (f *DateFilter) filterTomorrow(pivot time.Time) []*Todo { func (f *DateFilter) filterThisWeek(pivot time.Time) []*Todo { var ret []*Todo - begin := now.New(f.findSunday(pivot)).BeginningOfDay() + begin := now.New(f.FindSunday(pivot)).BeginningOfDay() end := begin.AddDate(0, 0, 7) for _, todo := range f.Todos { @@ -117,7 +117,7 @@ func (f *DateFilter) filterThisWeek(pivot time.Time) []*Todo { func (f *DateFilter) filterNextWeek(pivot time.Time) []*Todo { var ret []*Todo - begin := f.findSunday(pivot).AddDate(0, 0, 7) + begin := f.FindSunday(pivot).AddDate(0, 0, 7) end := begin.AddDate(0, 0, 7) for _, todo := range f.Todos { @@ -143,7 +143,7 @@ func (f *DateFilter) filterOverdue(pivot time.Time) []*Todo { return ret } -func (f *DateFilter) findSunday(pivot time.Time) time.Time { +func (f *DateFilter) FindSunday(pivot time.Time) time.Time { switch now.New(pivot).Weekday() { case time.Sunday: return pivot diff --git a/todolist/date_filter_test.go b/todolist/date_filter_test.go index c8b888b..8ee8db5 100644 --- a/todolist/date_filter_test.go +++ b/todolist/date_filter_test.go @@ -81,14 +81,18 @@ func TestFilterDay(t *testing.T) { assert := assert.New(t) var todos []*Todo - mondayTodo := &Todo{Id: 1, Subject: "one", Due: now.Sunday().AddDate(0, 0, 1).Format("2006-01-02")} - tuesdayTodo := &Todo{Id: 2, Subject: "two", Due: now.Sunday().AddDate(0, 0, 2).Format("2006-01-02")} + df := &DateFilter{} + sunday := df.FindSunday(time.Now()) + + mondayTodo := &Todo{Id: 1, Subject: "one", Due: sunday.AddDate(0, 0, 1).Format("2006-01-02")} + tuesdayTodo := &Todo{Id: 2, Subject: "two", Due: sunday.AddDate(0, 0, 2).Format("2006-01-02")} todos = append(todos, mondayTodo) todos = append(todos, tuesdayTodo) filter := NewDateFilter(todos) - filtered := filter.filterDay(now.BeginningOfDay(), time.Monday) + + filtered := filter.filterDay(sunday, time.Monday) assert.Equal(1, len(filtered)) assert.Equal(1, filtered[0].Id) |
