Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: 6dcdf6c826b1efccd84326043037cac9457707af
Timestamp: Fri, 09 Feb 2018 17:02:34 +0000 (6 years ago)

+24 -3 +/-2 browse
output tasks only from the last 24 hours by default, add more task output options
1diff --git a/main.go b/main.go
2index 2da6240..c2a07ce 100644
3--- a/main.go
4+++ b/main.go
5 @@ -58,11 +58,15 @@ func list(path *string) func(*cli.Cmd) {
6 return func(cmd *cli.Cmd) {
7 cmd.Spec = "[OPTIONS]"
8 var (
9- asJSON = cmd.BoolOpt("json", false, "output task history as JSON")
10- assend = cmd.BoolOpt("assend", true, "sort tasks assending in age")
11- limit = cmd.IntOpt("n limit", 0, "limit the number of results by n")
12+ asJSON = cmd.BoolOpt("json", false, "output task history as JSON")
13+ assend = cmd.BoolOpt("assend", false, "sort tasks assending in age")
14+ all = cmd.BoolOpt("a all", false, "output all tasks")
15+ limit = cmd.IntOpt("n limit", 0, "limit the number of results by n")
16+ duration = cmd.StringOpt("d duration", "24h", "show tasks within this duration")
17 )
18 cmd.Action = func() {
19+ duration, err := time.ParseDuration(*duration)
20+ maybe(err)
21 db, err := NewStore(*path)
22 maybe(err)
23 defer db.Close()
24 @@ -71,6 +75,9 @@ func list(path *string) func(*cli.Cmd) {
25 if *assend {
26 sort.Sort(sort.Reverse(ByID(tasks)))
27 }
28+ if !*all {
29+ tasks = After(time.Now().Add(-duration), tasks)
30+ }
31 if *limit > 0 && (len(tasks) > *limit) {
32 tasks = tasks[0:*limit]
33 }
34 diff --git a/types.go b/types.go
35index 67a5dff..ea36f1b 100644
36--- a/types.go
37+++ b/types.go
38 @@ -151,6 +151,20 @@ func (b ByID) Len() int { return len(b) }
39 func (b ByID) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
40 func (b ByID) Less(i, j int) bool { return b[i].ID < b[j].ID }
41
42+ // After returns tasks that were started after the
43+ // provided start time.
44+ func After(start time.Time, tasks []*Task) []*Task {
45+ filtered := []*Task{}
46+ for _, task := range tasks {
47+ if len(task.Pomodoros) > 0 {
48+ if start.Before(task.Pomodoros[0].Start) {
49+ filtered = append(filtered, task)
50+ }
51+ }
52+ }
53+ return filtered
54+ }
55+
56 // Pomodoro is a unit of time to spend working
57 // on a single task.
58 type Pomodoro struct {