-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
71 lines (58 loc) · 1.39 KB
/
report.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"time"
"github.com/spf13/cobra"
)
// reportCmd represents the report command
var reportCmd = &cobra.Command{
Use: "report",
Short: "A brief description of your command",
Long: ``,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
tasks := TaskList{}
tasks.Load("tasks.json")
if len(args) == 0 {
tasks.List()
return
}
reportType := args[0]
if reportType == "standup" {
filteredTasks := TaskList{}
for _, task := range tasks {
if task.Status == Done && isTodayOrYesterday(task.CompletedAt) {
filteredTasks.AddTask(task)
} else if task.Status == InProgress {
filteredUpdates := []TaskUpdate{}
for _, update := range task.Updates {
if isTodayOrYesterday(update.WrittenAt) {
filteredUpdates = append(filteredUpdates, update)
}
}
if len(filteredUpdates) > 0 {
task.Updates = filteredUpdates
filteredTasks.AddTask(task)
}
}
}
filteredTasks.List()
}
},
}
func isTodayOrYesterday(t time.Time) bool {
now := time.Now()
yesterday := now.AddDate(0, 0, -1)
if t.Year() == now.Year() && t.YearDay() == now.YearDay() {
return true
} else if t.Year() == yesterday.Year() && t.YearDay() == yesterday.YearDay() {
return true
} else {
return false
}
}
func init() {
rootCmd.AddCommand(reportCmd)
}