diff --git a/main.go b/main.go index 2da6240..c2a07ce 100644 --- a/main.go +++ b/main.go @@ -58,11 +58,15 @@ func list(path *string) func(*cli.Cmd) { return func(cmd *cli.Cmd) { cmd.Spec = "[OPTIONS]" var ( - asJSON = cmd.BoolOpt("json", false, "output task history as JSON") - assend = cmd.BoolOpt("assend", true, "sort tasks assending in age") - limit = cmd.IntOpt("n limit", 0, "limit the number of results by n") + asJSON = cmd.BoolOpt("json", false, "output task history as JSON") + assend = cmd.BoolOpt("assend", false, "sort tasks assending in age") + all = cmd.BoolOpt("a all", false, "output all tasks") + limit = cmd.IntOpt("n limit", 0, "limit the number of results by n") + duration = cmd.StringOpt("d duration", "24h", "show tasks within this duration") ) cmd.Action = func() { + duration, err := time.ParseDuration(*duration) + maybe(err) db, err := NewStore(*path) maybe(err) defer db.Close() @@ -71,6 +75,9 @@ func list(path *string) func(*cli.Cmd) { if *assend { sort.Sort(sort.Reverse(ByID(tasks))) } + if !*all { + tasks = After(time.Now().Add(-duration), tasks) + } if *limit > 0 && (len(tasks) > *limit) { tasks = tasks[0:*limit] } diff --git a/types.go b/types.go index 67a5dff..ea36f1b 100644 --- a/types.go +++ b/types.go @@ -151,6 +151,20 @@ func (b ByID) Len() int { return len(b) } func (b ByID) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b ByID) Less(i, j int) bool { return b[i].ID < b[j].ID } +// After returns tasks that were started after the +// provided start time. +func After(start time.Time, tasks []*Task) []*Task { + filtered := []*Task{} + for _, task := range tasks { + if len(task.Pomodoros) > 0 { + if start.Before(task.Pomodoros[0].Start) { + filtered = append(filtered, task) + } + } + } + return filtered +} + // Pomodoro is a unit of time to spend working // on a single task. type Pomodoro struct {