diff options
| author | Ashish Vijayaram <initrd@gmail.com> | 2017-04-17 12:36:46 -0700 |
|---|---|---|
| committer | Ashish Vijayaram <initrd@gmail.com> | 2017-04-17 12:36:46 -0700 |
| commit | a0db863a64d1530b15a18725d323e87776a8a52c (patch) | |
| tree | 91b8b8d5c17103cd16532939fe23a2b2f19a1239 /todolist | |
| parent | e118736cf7df17dc10822fab36af7407c7e110a6 (diff) | |
Add support for showing tasks due the previous week.
This is useful for those who need a report of entries from last week.
Diffstat (limited to 'todolist')
| -rw-r--r-- | todolist/date_filter.go | 17 | ||||
| -rw-r--r-- | todolist/parser.go | 3 |
2 files changed, 20 insertions, 0 deletions
diff --git a/todolist/date_filter.go b/todolist/date_filter.go index b56f117..fb06682 100644 --- a/todolist/date_filter.go +++ b/todolist/date_filter.go @@ -45,6 +45,8 @@ func (f *DateFilter) FilterDate(input string) []*Todo { return f.filterThisWeek(bod(time.Now())) case match == "due next week": return f.filterNextWeek(bod(time.Now())) + case match == "due last week": + return f.filterLastWeek(bod(time.Now())) case match == "overdue": return f.filterOverdue(bod(time.Now())) } @@ -130,6 +132,21 @@ func (f *DateFilter) filterNextWeek(pivot time.Time) []*Todo { return ret } +func (f *DateFilter) filterLastWeek(pivot time.Time) []*Todo { + var ret []*Todo + + begin := f.FindSunday(pivot).AddDate(0, 0, -7) + end := begin.AddDate(0, 0, 7) + + for _, todo := range f.Todos { + dueTime, _ := time.ParseInLocation("2006-01-02", todo.Due, f.Location) + if begin.Before(dueTime) && end.After(dueTime) { + ret = append(ret, todo) + } + } + return ret +} + func (f *DateFilter) filterOverdue(pivot time.Time) []*Todo { var ret []*Todo diff --git a/todolist/parser.go b/todolist/parser.go index ca5083a..1f070c3 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -94,6 +94,9 @@ func (p *Parser) Due(input string, day time.Time) string { return p.saturday(day) case "sunday", "sun": return p.sunday(day) + case "last week": + n := bod(time.Now()) + return getNearestMonday(n).AddDate(0, 0, -7).Format("2006-01-02") case "next week": n := bod(time.Now()) return getNearestMonday(n).AddDate(0, 0, 7).Format("2006-01-02") |
