summaryrefslogtreecommitdiff
path: root/internal/task/stats.go
blob: b306687ddbdf4cad1ea95a22ecdc45dfddba8e26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package task

import "time"

// TotalTasks returns the number of tasks provided.
func TotalTasks(tasks []Task) int {
	return len(tasks)
}

// InProgressTasks returns the number of tasks that have been started and are not completed.
func InProgressTasks(tasks []Task) int {
	count := 0
	for _, t := range tasks {
		if t.Status == "completed" {
			continue
		}
		if t.Start != "" {
			count++
		}
	}
	return count
}

// DueTasks returns the number of tasks with a due date that is not in the future.
func DueTasks(tasks []Task, now time.Time) int {
	count := 0
	for _, t := range tasks {
		if t.Status == "completed" || t.Due == "" {
			continue
		}
		ts, err := time.Parse(DateFormat, t.Due)
		if err != nil {
			continue
		}
		if !ts.After(now) {
			count++
		}
	}
	return count
}